I am going to be executing an Update stored procedure from .NET. I want the following logic in T-SQL, however I can’t seem to find out how this can be done.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE sp_UpdateTable
@TableID int,
@StartTime1 datetime,
@EndTime1 datetime
AS
BEGIN
SET NOCOUNT ON;
UPDATE [Table]
SET [StartTime1] = WAS_PASSED_FROM_CODE(@StartTime1, @StartTime1, [StartTime1])
,[EndTime1] = WAS_PASSED_FROM_CODE(@EndTime1, @EndTime1, [EndTime1])
WHERE TableID = @TableID
END
GO
Okay, so what I am basically looking for is a way to determine whether the parameter was specified from code, (hence WAS_PASSED_FROM_CODE) if the parameter was specified from code, then update that column to the specified value, else, leave intact (update to existing value).
Is this possible?
Note that in this case it is valid for the code to pass NULL, in that case, the column should update to NULL.
Make your parameters default to
NULLand then useISNULL. If the parameter is not specified it will beNULLEdit: Given that NULL is a valid value, add two additional parameters to marked whether or not the date parameters are specified.