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 2005 Forums
 Transact-SQL (2005)
 Update the multiple Flag

Author  Topic 

amsqlguy
Yak Posting Veteran

89 Posts

Posted - 2009-06-26 : 12:59:34
Guys,

I have table which has a flag that indicates if the empid is populated mutliple times how do I update the flag in case of multiple employee ids. Any suggestions and inputs would help

EMPID MULTIPLEFLAG
1 N
2 N
3 Y
3 Y

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-26 : 13:02:33
Try this:

update t1
set MULTIPLEFLAG='Y'
from table t1
join
(select EMPID from table group by EMPID having count(*) > 1)dt
on dt.EMPID = t1.EMPID



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-26 : 13:51:31
[code]UPDATE t
SET t.MULTIPLEFLAG='Y'
FROM (SELECT COUNT(EMPID) OVER (PARTITION BY EMPID) AS Occur, MULTIPLEFLAG
FROM YourTable)t
WHERE t.Occur>1
[/code]
Go to Top of Page
   

- Advertisement -