• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

sql server conditional update

Need a sql statement that will do the following pseudocode

if field_1 = n1 then set field_2 = n2
if field_1 = o1 then set field_2 = o2
.
.
.
if field_1 = z1 then set field_2 = z2

please advise.
0
THz_
Asked:
THz_
1 Solution
 
reb73Commented:
Something like this -
UPDATE <table>
SET field_2 = CASE field 1 
		WHEN n1 then n2
		WHEN o1 then o2
		....
	        ELSE field_2
              END

Open in new window

0
 
THz_Author Commented:
Will check it out and let you know. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now