Jshee
Jshee

Reputation: 2686

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

Upvotes: 0

Views: 687

Answers (2)

onedaywhen
onedaywhen

Reputation: 57023

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;

Upvotes: 0

BugFinder
BugFinder

Reputation: 17858

How about, you could do

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

Upvotes: 7

Related Questions