Solution_id (Primary key, Int)
Col1 (varchar)
Col2 (varchar)
Col3 (varchar)
Col4 (varchar)
Col5 (varchar)
I am writing a stored procedure to update this table. There are 6 input parameters for the above 6 columns.
@Attached_File1 VARCHAR(MAX),
@Attached_File2 VARCHAR(MAX),
@Attached_File3 VARCHAR(MAX),
@Attached_File4 VARCHAR(MAX),
@Attached_File5 VARCHAR(MAX),
@Ticket_ID BIGINT
I want to write a SQL query which will update the table with the values specified in the input parameters. BUT I must not overwrite the attachment columns with null. I mean I need to use only those parameters which contains data.
For example, if the table has a row
[10, "aaa", "bbb", "efg", null, null]
and the input parameters are
(10, null, null, "mno", "ddd", null)
then after the update the row will become
[10, "aaa", "bbb", "mno", "ddd", null]
How to check for null/empty strings and generate the update query accordingly to achieve this?
Is this something like you’re after?
ISNULLtakes two values, if the first one is not null then it is used, otherwise the 2nd value is used.See MSDN for more information on
ISNULLUpdate
I’ve just noticed your comment at the end, which talks about empty strings…
In which case, you could do the following…
This uses the
NULLIFstatement which takes two values, if the first value is the same as the second value, then NULL is returned, otherwise it returns the first value.See MSDN for more information on
NULLIF