Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditional update
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Conditional update
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01187142
Message ID:
01187142
Views:
78
I would like to write a "conditional" update statement, something like this:
UPDATE MyTable
SET    field1 = @field1,
       field2 = IIF(LEN(@field2)>0, @field2, field2),
       field3 = @field3
WHERE  field4 = @field4
To put this into words I want to update field2 only if the passed @field2 (nvarchar) parameter is non-empty string.

Is the above syntax the best syntax to use for this, or is there a better way?

Thanks,
Einar
Semper ubi sub ubi.
Next
Reply
Map
View

Click here to load this message in the networking platform