472,123 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,123 software developers and data experts.

Updating multiple columns with several conditions

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
2 7387
deepuv04
227 Expert 100+
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
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.

Similar topics

7 posts views Thread by Billy Jacobs | last post: by
2 posts views Thread by ray well | last post: by
3 posts views Thread by Leif Neland | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.