I'm trying to use ROW_NUMBER()
function to give me distinct groups of my data but keep getting an Invalid column name error. Here is my query:
SELECT
ROW_NUMBER() OVER (PARTITION BY Access.Number ORDER BY Access.Time) dstbadge,
Access.Event AS 'Event',
Access.Reader AS 'Reader',
Access.Time AS 'Event Time UTC',
Access.LastName AS 'Last',
Access.FirstName AS 'First',
Access.Number AS 'EmpNum'
FROM
Access
WHERE
dstbadge = 1
The above query would provide distinct groups of Access.numbers
ordered by Access time and return only the first row in each group.
I get this error:
Msg 207, Level 16, State 1, Line 59
Invalid column name 'dstbadge'