Share via

SSRS report builder 3.0. SQL recordset help

Jetramsey 21 Reputation points
2021-02-26T22:00:12.24+00:00

I’ve simplified this set of data and here’s my goal. For each EVENT with more than one EMP (Employee), I want just a record set just showing the EVENT, EMP and DATE of just the EMP with the first Date assigned. So, one line for each EVENT listing just one EMP with the first Date assigned.

Event Emp Date
001 SMITH 2021-02-22 11:48:00
001 JONES 2021-02-22 11:35:00
002 BIRD 2021-02-22 12:21:00
002 SMITH 2021-02-22 11:15:00
002 HUNT 2021-02-22 12:39:00
003 JOHNS 2021-02-22 14:29:00
004 SMITH 2021-02-22 14:35:00

So, with Records above, I just want to see:

Event Emp Date
001 JONES 2021-02-22 11:35:00
002 SMITH 2021-02-22 11:15:00
003 JOHNS 2021-02-22 14:29:00
004 SMITH 2021-02-22 14:35:00

Removed should be:

001 SMITH 2021-02-22 11:48:00
002 BIRD 2021-02-22 12:21:00
002 HUNT 2021-02-22 12:39:00

TIA

SQL Server Reporting Services
SQL Server Reporting Services

A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Olaf Helper 47,621 Reputation points
2021-02-27T06:29:50.267+00:00

Hello,

Aggregate on Event to get the first (lowest/min) date and then JOIN, like

;WITH cte AS
    (SELECT Event, MIN(Date) AS MinDate
     FROM yourTable AS T
     GROUP BY Event)
SELECT T.*
FROM yourTable AS T
     INNER JOIN
     cte
         ON T.Event = cte.Event
            AND T.Date = cte.MinDate

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.