March 24, 2007 at 10:49 am
Hi all, I have this problem of update a column depending on the value of certain column. My data looks like below.
Fld1 Fld2 Fld3 Fld4 Fld5 Fld6 Total1
1 10 15 3 20 10 0
3 10 15 2 40 30 0
5 20 25 0
Where Fld1 and Fld4 are always an integer either an odd or even number.
I need to add the value of Fld2 to Total1 if Fld1 is an odd integer and if Fld4 is an odd integer, add Fld5 to the total1.
Result should looks like below.
Fld1 Fld2 Fld3 Fld4 Fld5 Fld6 Total1
1 10 15 3 20 10 30
3 10 15 2 40 30 10
5 20 25 20
Any help is appreciated. Thanks.
March 25, 2007 at 8:16 am
I hope u requirement can be met using CASE statement. try with tat.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
March 25, 2007 at 2:46 pm
Something like this
update xx
set fld4 = fld1 + total
where fld1 mod 2 = 0
for one of them. The other would be
update xx
set fld5 = fld2 + total
where fld1 mod 2 = 1
Follow me on Twitter: http://www.twitter.com/way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
March 25, 2007 at 3:22 pm
Steve, thanks for the prompty reply. Your solution works. I am hoping that I can do this in one pass. The reason is the real data contents 36 sets of these data in one row. My sample data was only 2 sets. Any help is appreciated. Thanks.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply