Hi,
I have a Sharepoint List called Candidates.
Each Candidate has a Status which varies between 9 different values.
For each Candidate there may be multiple Status fields.
For Example
Candidate Name Status Date when Status was created/modified ID
John Doe New 20/07/2011 1
John Doe Shortlisted 21/07/2011 1
John Doe Shortlisted 22/07/2011 1
John Doe Reject 23/07/2011 1
Jane Doe New 20/07/2011 2
Jane Doe Shortlisted 22/07/2011 2
Jane Doe Shortlisted 23/07/2011 2
Jane Doe Shortlisted 23/07/2011 2
Jane Doe Joined 23/07/2011 2
So now I want a query(to generate a report) which gets the Candidate Name, and his latest Status for each status value... I mean that the query should generate the table below.
Candidate Name Status Date when Status was created/modified
John Doe New 20/07/2011
John Doe Shortlisted 22/07/2011
John Doe Reject 23/07/2011
Jane Doe New 20/07/2011
Jane Doe Shortlisted 23/07/2011
Jane Doe Joined 23/07/2011
So as you can see I need to get only the latest Shortlisted value or the latest Joined value (if there are any multiple values with status Joined)
What I am able to get so far is for each name I am able to get the latest Status
ie
Candidate Name Status Date when Status was created/modified
John Doe Reject 23/07/2011
Jane Doe Joined 23/07/2011
thru the following query:
SELECT [tp_ID],
[nvarchar14],
[tp_Modified]
FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY [tp_ID] ORDER BY [tp_Modified] DESC) AS rn,
[tp_ID],
[nvarchar14],
[tp_Modified]
FROM [WSS_Intvw666Mgmt].[dbo].[AllUserData]
WHERE [tp_ListId] = 'b126efb6-1239-4b8a-978b-897960078552'
) a
WHERE rn = 1
In this query
tp_ID is the Candidate ID... which is unique
nvarchar14 is the Status
and tp_Modified is the date when the Status was created/modified
Can anyone please help me out with this?