By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

Sql update command question

P: 3
Hi,

I want to know are there any ways to do the statement below in one SQL command?

update [table_a] set [column_a] = 'A' where id in (1,2,3)
update [table_a] set [column_a] = 'B' where id in (4,5,6)

(above statement use 2 times for updating)

PS. thanks for advise if it possible to do :D
Oct 19 '09 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
Yes, use the CASE statement.

Expand|Select|Wrap|Line Numbers
  1.  
  2. update [table_a] 
  3. set [column_a] = 
  4. case when id in (1,2,3) then 'A' when id in (4,5,6) then 'B' else NULL end
  5.  
  6.  
Happy Coding!!!

--- CK
Oct 19 '09 #2

P: 3
It's works ! thank you very much

however It's modified all records in the table, if i'd like to modify only in the set of ids, is it possible?
Oct 20 '09 #3

P: 3
I got the solution now, it's just add the 'where' clause after end case :D
Oct 20 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.