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
-- 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.