I save multiple records into my SQL Server table in one go, 5 records of data to be exact.
The data gets saved fine but I am not sure how to update all those records at once.
This is what I have. Please assist me on how to do the update part of my SQL Server procedure in order to update all those records in one go.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_UserInsertUpdate]
@UserID INT,
@Monday VARCHAR(100),
@MondayAM BIT,
@MondayPM BIT,
@MondayNA BIT,
@Tuesday VARCHAR(100),
@TuesdayAM BIT,
@TuesdayPM BIT,
@TuesdayNA BIT,
@Wednesday VARCHAR(100),
@WednesdayAM BIT,
@WednesdayPM BIT,
@WednesdayNA BIT,
@Thursday VARCHAR(100),
@ThursdayAM BIT,
@ThursdayPM BIT,
@ThursdayNA BIT,
@Friday VARCHAR(100),
@FridayAM BIT,
@FridayPM BIT,
@FridayNA BIT
AS
BEGIN
IF (@UserID = 0)
BEGIN
INSERT INTO tb_UserAvailability (Day, AM, PM, NotAvailable)
VALUES (@Monday, @MondayAM, @MondayPM, @MondayNA),
(@Tuesday, @TuesdayAM, @TuesdayPM, @TuesdayNA),
(@Wednesday, @WednesdayAM, @WednesdayPM, @WednesdayNA),
(@Thursday, @ThursdayAM, @ThursdayPM, @ThursdayNA),
(@Friday, @FridayAM, @FridayPM, @FridayNA)
END
ELSE
BEGIN
UPDATE [dbo].[tb_UserAvailability]
SET -- Update statement here. Need help.
WHERE UserID = @UserID
END
END
Thank you
sp_prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoidsp_and use something else as a prefix - or no prefix at all!