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

Updating multiple columns with several conditions

P: 16
Hi,

I have a table which has columns name, date1, date2.
Through 'Or' condition, i can update name but to update date1 and date2 I have another condition. ID1 matches, date1 will be updated and date2 on ID2.
How to set these columns in a single query?


Thanks,
Prat
Jun 3 '08 #1
Share this Question
Share on Google+
2 Replies


deepuv04
Expert 100+
P: 227
Hi,

I have a table which has columns name, date1, date2.
Through 'Or' condition, i can update name but to update date1 and date2 I have another condition. ID1 matches, date1 will be updated and date2 on ID2.
How to set these columns in a single query?


Thanks,
Prat
hi,
try something like
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table_Name
  2. SET Name = @New_Name,
  3.     Date1 = CASE @Value WHEN ID1 THEN @New_Date
  4.             ELSE Date1 END,
  5.     Date2 = CASE @Value WHEN ID2 THEN @New_Date
  6.             ELSE Date2 END
  7. WHERE Your_Condition
  8.  
thanks
Jun 3 '08 #2

P: 16
Thanks a lot! It works



hi,
try something like
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table_Name
  2. SET Name = @New_Name,
  3.     Date1 = CASE @Value WHEN ID1 THEN @New_Date
  4.             ELSE Date1 END,
  5.     Date2 = CASE @Value WHEN ID2 THEN @New_Date
  6.             ELSE Date2 END
  7. WHERE Your_Condition
  8.  
thanks
Jun 3 '08 #3

Post your reply

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