Use below...CREATE TABLE [dbo].[rank] ( [pk_id] [int] IDENTITY (1, 1) NOT NULL , [care_id] INT, [tid] INT, [tdate] [datetime] NOT NULL) ON [PRIMARY]GOINSERT INTO dbo.[rank](CARE_ID, tid, tdate) VALUES(369, 117, '2010/07/28'),(481,63,'2010/07/09'), (834,622,'2012/01/01'), (2222, 434, '2011/05/11'),(2246,138, '2012/07/01'), (2246, 413, '2012/07/01'),(2246,768, '2012/07/01')select [R1].[pk_id],[R1].[care_id], [R1].tid, [R1].[tdate], rank =(select count(distinct [R2].[tid])from [rank] [R2]where [R1].[care_id] = R2.care_id AND r1.tid <= [R2].[tid])from [rank] [R1]WHERE (select count(distinct [R2].[tid])from [rank] [R2]where [R1].[care_id] = R2.care_id AND r1.tid <= [R2].[tid]) = 1order by [rank]DROP TABLE [rank]
Visit www.sqlsaga.com for more t-sql snippets and BI related how to's.