I'm trying to run the following query:
With T As (Select A.TerminationDate,
B.TerminationApproach,
B.Date,
A.UserName,
A.LastName,
A.FirstName,
Case
When B.Date <= A.TerminationDate Then 0
Else 1
End As EvalCheck
From A
Left Join B On B.ChangedUser = A.UserName)
Select T.UserName,
T.seqnum,
T.TerminationDate,
T.TerminationApproach,
T.Date,
T.LastName,
T.FirstName,
T.EvalCheck
From (Select T.*,
Row_Number() Over (Partition By T.UserName Order By T.Date) As
seqnum
From T) T;
Where T.seqnum = 1
And get the following error on my SQL database when trying to execute it:
Maybe there is a better way to do this query and get rid of the error?