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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Populate flag field

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2008-02-01 : 16:09:44
Guys,

I have scenario where I have to update flag field based on the following data combination.

Party_id count seq flag (TO BE POPULATED)
____________________________________
213777 1 1 Y
213777 2 1 N
213777 2 2 Y
213778 1 1 N
213778 1 2 N
213778 1 3 Y
213778 2 1 N

The logic to populate flag = 'Y' is to pick up the max seq field for the same combination of PARTY_ID and COUNT.

Any suggestions and inputs would help

Thanks


TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-01 : 16:32:48
[code]
update t set
t.Flag = 'Y'
from (
select Party_id
,[count]
,max(seq) seq
from T
group by Party_id
,[count]
) d
join T t
on t.party_id = d.party_id
and t.[count] = d.[count]
and t.[seq] = d.[seq]
[/code]

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -