From: rodchar on
hey all,

i have a sql like so:

update mytable
set mycol=val
from
(
if (cond)
begin
select myval from t1
end
else
begin
select * from t2
end
) tbl

is there a way to make the if(cond) work? probably doesn't look like a good
idea anyway?

thanks,
rodchar
From: Plamen Ratchev on
It will be best to simply use IF statement and run two separate queries based on the conditions:

IF (cond)
UPDATE mytable ... FROM t1
ELSE
UPDATE mytable ... FROM t2

--
Plamen Ratchev
http://www.SQLStudio.com
From: --CELKO-- on

UPDATE Fooobar
SET x
= CASE WHEN <search condition>
THEN <scalar expression #1>
ELSE <scalar expression #2> END;

From: rodchar on
thanks for the help,
rod.

"Plamen Ratchev" wrote:

> It will be best to simply use IF statement and run two separate queries based on the conditions:
>
> IF (cond)
> UPDATE mytable ... FROM t1
> ELSE
> UPDATE mytable ... FROM t2
>
> --
> Plamen Ratchev
> http://www.SQLStudio.com
> .
>