From: rodchar on 15 Apr 2010 15:51 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 15 Apr 2010 18:05 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 16 Apr 2010 09:42 UPDATE Fooobar SET x = CASE WHEN <search condition> THEN <scalar expression #1> ELSE <scalar expression #2> END;
From: rodchar on 16 Apr 2010 09:52 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 > . >
|
Pages: 1 Prev: SP in IN clause Next: SQLCLR Table-Valued Function and NULL value |