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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE with more than one condition

Status
Not open for further replies.

pradchal1

Programmer
Nov 10, 2004
31
FR
I am trying to UPDATE a table and my syntax:

Update table1
Set
Name = "Held"
where Name_Hold = 'Yes'
OR
Set
Address = "Held"
where Address_Hold = 'Yes'
OR
Set Phone = "Held"
where Phone_Hold = 'Yes'



is not working.

Any help would be appreciated. Thanks
 
This syntax may work. Theoretically, if the Name_Hold is not 'y' then the value of the name field should be unchanged. I strongly suggest that you test this really well before putting it in to production.

Code:
Update Table1
Set    Name = Case When Name_Hold = 'Y' Then 'Held' Else Name End,
       Address = Case When Address_Hold = 'Y' Then 'Held' Else Address End,
       Phone = Case When Phone_Hold = 'Y' Then 'Held' Else Phone End

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Try
Code:
Update table1
Set Name = 'Held'
Where Name_hold = 'yes' OR
      Address_hold = 'Yes' OR
      Phone_hold = 'Yes'
 
As a side note... what is wrong with three (3) separated UPDATEs?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
I should mention that my code differs from Denis's code. You should study both of them carfully and chose wisely.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for all your suugestion. But I figured out the easiest, clear and efficient would be to go with three Updates like Vongrunt suggested.

Thanks again to you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top