update field that could be null in stored procedure
I have a table that contains two columns which could be null.
I want to build a stored procedure to edit that table. in the stored
procedure I did this:
@ID INT,
@newBuildingName NVARCHAR(250),
@newLocation NVARCHAR(3000),
@newImage VARBINARY(MAX) = NULL,
@newNote NVARCHAR(3000) = NULL,
@result BIT OUTPUT
Not I can't decide in this point if the user has entered values for
newImage or newNote fields, so I can't say
UPDATE myTable SET image = @newImage, note = @newNote
because these two fields might already have values and in this way I would
be deleting those vaules,
what should I do?
What I thing is make an if-else statement and try if the first field is
null so make my update without it and then if my second field is null then
make my update statement without it and if neither of them is null then
make a full update statement but I thing that this is a very teduis
process.
Is there any other solution plesae ?
Thanks in advance
No comments:
Post a Comment