Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-29 : 10:44:23
|
HiI have table like this...A B C D 75 5 70 075 92 17 175 508 433 175 2116 2041 175 8680 8605 1 I have to check the condition is A<B its true D should be 1(when the condition meet first row is update to 1 else all rows are update 0)I want like this...A B C D 75 5 70 075 92 17 175 508 433 075 2116 2041 075 8680 8605 0 Help out on this...-------------------------R.. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-07-29 : 10:52:28
|
| Here is one waydeclare @t table (A int, B int, C int, D int)insert @tselect 75, 5, 70, 0 union allselect 75, 92, 17, 1 union allselect 75, 508, 433, 1 union allselect 75, 2116, 2041, 1 union allselect 75, 8680, 8605, 1 update @t set D = 0update Tset T.D = 1from @t T inner join (select row_number() over(partition by A order by B ) as seq,* from @twhere A<B) T1on T.A = T1.A and T.B = T1.B and T.C = T1.Cwhere T1.seq = 1select * from @tResult-------A B C D----------- ----------- ----------- -----------75 5 70 075 92 17 175 508 433 075 2116 2041 075 8680 8605 0 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-29 : 11:06:11
|
| One of the methodsdeclare @t table(A int, B int, C int, D int)insert into @tselect 75, 5, 70, 0 union allselect 75, 92, 17, 1 union allselect 75, 508, 433, 1 union allselect 75, 2116, 2041, 1 union allselect 75, 8680, 8605, 1select * from @tupdate @tset d=case when a<b then 1 else 0 endfrom @tupdate tset d=case when sno=1 and d=1 then 1 else 0 endfrom(select *,row_number() over (partition by d order by B) as sno from @t) as tselect * from @tMadhivananFailing to plan is Planning to fail |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-29 : 11:09:59
|
| Hi vijayisonlyThanks a lot..friend-------------------------R.. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-07-29 : 11:11:45
|
welcome |
 |
|
|
|
|
|
|
|