In the training course and manual was a stored procedure that was referred to called an Upsert. Could you please give me a T-SQL example of this sproc for updating/inserting a group records at one time.
Thanks,
Jeff
You might look at the training manual as I believe there is a sample in there from Ben's session.
CREATE PROC [dbo].[Book_upsert]
@Book_pk int,
@Title varchar(30),
AS
SET NOCOUNT ON
IF @Book_pk = 0
BEGIN
INSERT INTO Book ([Title]) VALUES (@Title)
SELECT SCOPE_IDENTITY() As InsertedID
END
ELSE
UPDATE Book SET [Title] = @Title WHERE [Book_pk] = @Book_pk
SET NOCOUNT OFF
-- Turn off row countingSET NOCOUNT ON;
-- Declare variablesDECLARE @recCount INT;
-- Perform a scalar query to determine if the -- record already existsSELECT @recCount = COUNT(* )FROM UserLocationsWHERE ul_us_pk = @userPk
-- Now determine how to update the recordIF @recCount > 0 BEGIN -- Update the existing record UPDATE UserLocations SET ul_vel_pk = @eventLocationPk WHERE ul_us_pk = @userPk ENDELSE BEGIN -- Create the location record INSERT INTO UserLocations ( ul_us_pk, ul_vel_pk) VALUES ( @userPk, @eventLocationPk) END END
Thank you for taking the time to send me the example. It was what I was looking for.