I have a staging table (in SQL SERVER 2008) with nullable fields.
I want to Insert or Update the records from the staging table to main table.
During this I want a comparison to be done
Update main
set main.field1 = (
if(staging.field1 isnull)
then ----
else if(staging.field2 isnull)
then ----
else
then
)
How can I embed the above condition in my insert and update statements?
The (sort of) equivalent is to use CASE
expressions:
UPDATE main
SET main.field1 =
CASE
WHEN staging.field1 IS NULL
THEN --
WHEN staging.field2 IS NULL
THEN --
ELSE --
END;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With