开发者

Select then update - sql question

How do I make this query first find all professors开发者_开发问答 whose picture IS NULL and THEN update with a new value for column 'picpath'

I have:

SELECT * FROM Professor
WHERE picpath IS NULL;

Is it possible to form this all in a subquery perhaps? Can someone help


How about, you could do

update professor set picpath=<newvaluehere> where picpath is null


Using SQL Server's OUTPUT clause (MSSQL208 and above) you can kinds of do the same but the other way around i.e. UPDATE then SELECT the affected rows e.g.

UPDATE professor 
   SET picpath = 'C:\'
OUTPUT inserted.*
 WHERE picpath IS NULL;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜