开发者

Select then update - sql question

开发者 https://www.devze.com 2023-02-21 23:46 出处:网络
How do I make this query first find all professors开发者_开发问答 whose picture IS NULL and THEN update with a new value for column \'picpath\'

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

精彩评论

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