Hi, I am trying to write a SQL query that will run through a PowerShell script to get the staff members most current job position. To do this I am using the [EndDate] field as this *should* relate to the current role they hold.
Here is the query I am using.
SQL
SELECTsjp.[ID],sjp.[StaffJobPositionsSeq],sjp.[EndDate],sjp.[JobPositionsSeq]FROM[dbname].[dbo].[StaffJobPositions]assjp,[dbname].[dbo].[Staff]asstaffwheresjp.ID=staff.IDandstaff.ActiveFlag='1'andsjp.EndDate=(selecttop(1)EndDatefrom[dbname].[dbo].[StaffJobPositions]orderby[dbname].[dbo].[StaffJobPositions].[EndDate]desc)orderbysjp.EndDatedesc
The problem with this query is it only returns one user (the user that holds the highest date value for when their role ends) rather than all user who are currently active (ActiveFlag = '1') but only...