- , temp, . , . , ( LastEffectiveDate):
DECLARE @tmp table
(
Sequence INT IDENTITY,
UserID BIGINT,
JobCodeID BIGINT,
LastEffectiveDate DATETIME
)
INSERT INTO @tmp VALUES ( 1, 5, '1/1/2010')
INSERT INTO @tmp VALUES ( 1, 5, '1/2/2010')
INSERT INTO @tmp VALUES ( 1, 6, '1/3/2010')
INSERT INTO @tmp VALUES ( 1, 5, '1/4/2010')
INSERT INTO @tmp VALUES ( 1, 1, '1/5/2010')
INSERT INTO @tmp VALUES ( 1, 1, '1/6/2010')
SELECT TOP 1 JobCodeID, LastEffectiveDate
FROM @tmp
UNION ALL
SELECT t2.JobCodeID, t2.LastEffectiveDate
FROM @tmp t1
INNER JOIN
@tmp t2
ON t1.Sequence + 1 = t2.Sequence
WHERE t1.JobCodeID <> t2.JobCodeID
, , , , , .