Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Building UPDATE dynamically
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01596792
Message ID:
01596795
Views:
38
>>By default all declared variables will be NULL. Assuming you will not be having NULL values in your XML file you can do
>>
>>update myTable SET Fld1Name = COALESCE(@Fld1Value, Fld1Name), etc.
>
>I didn't know that I can skip declaring a variable. I thought that I always have to do
>declare @MyVarName INT before using it.
>
>I have never used COALESCE() either. The approach you describe should work. I will test it.
>Thank you.

This is not what I said. You can not skip DECLARE in SQL Server, all variables must be declared. Once a variable is declared, it will be NULL. The select @FidlVar = ...
doesn't change the value if that select statement returns 0 rows. So, if you never going to have NULL values passed in your XML, then the solution I suggested is the simplest one.

The alternative is to build the dynamic SQL which is also simple.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform