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

update muiltple columns

Status
Not open for further replies.

ironvid

IS-IT--Management
Sep 2, 2003
10
GB
Hi

At the moment I update a single column with the following query:

update example_Table set finished to ='yes' where ( box='123')

which works fine

I now want to be able to update 3 columns in my table at the same time without having to do 3 querys

so i want to beable to update

finished column=yes
location = pk4
row=lfront

all where i specify the box number

thanks for any help

regards...Stephen
 
Code:
update example_Table 
  set finished ='yes' ,
      location = 'pk4',
      row = 'lfront'
 where box='123'
 
what if where clause is also different for different columns...?
is any way the following in one query

update example_Table set finished ='yes' where box='123'
update example_Table set location ='pk4' where No =11
update example_Table set row = 'lfront' where box='222'

i think there is no way but may be i am wrong...!
 
Code:
set quoted_identifier on
update example_Table 
set finished = case when box = '123' then 'yes' 
  else finished end,
location = case when "NO" = 11 then 'pk4'
  else location end,
 "ROW" = case when box = '222' then 'front'
  else "ROW" end
where box in ('123','222')
  or "NO" = 11

(shouldn't use row or no as columnnames though.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top