469,126 Members | 1,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,126 developers. It's quick & easy.

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 7218
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.