Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update with conditional variable 1

Status
Not open for further replies.

anrver

Programmer
Jun 24, 2002
12
0
0
CH
I'm updating a column as follows :

UPDATE table
SET Office = 'ANR'
WHERE Department = 'SE'
GO
UPDATE table
SET Office = 'BRU'
WHERE Department = 'AI'

Is there a way I can do this in one run ? I was thinking about setting a variable depending on the 'Department' value and updating the column with this variable.



Erik Verstichel
Panalpina World Transport.
Antwerp, Belgium
 
UPDATE table
SET Office = CASE WHEN Department = 'SE' THEN 'ANR' ELSE 'BRU' END
WHERE Department in ('SE','AI')

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top