Declare @table table (EMPIID int, NAME VARCHAR(10),Updatedate datetime)
INSERT into @table values(111,'Muthu','02/13/2014')
INSERT into @table values(222,'Mari','02/14/2014')
INSERT into @table values(222,'Raja','02/13/2014')
INSERT into @table values(222,'Muthu','02/14/2014')
INSERT into @table values(333,null,null)
INSERT into @table values(444,'Rahul','02/02/2014')
Select * from @table
I need a output from above table with below logic.
1.For the Emp name that are tied to more than one empid then don’t use these empname for any empids, need to display with some other dumppy name with emp id.
here name muthu belongs to empid 222 so that i need an output for this situation
111 marimuthu '02/13/2014' -- no need to display name muthu belongs to 222.
2) For rest of the names pick the one to the empid if only one name found; otherwise pick the Names with greatest updateDate.
So my final output for above table records should be comes like this
Empid | Name | updateDate |
1111 | marimuthu | null |
2222 | muthu | 02/14/2014 |
3333 | Muhtu00003333(dumppy) | null |
4444 | Rahul | 02/02/2014 |