Query data for the last day of previous month into SSRS Report Cell
I'm in the process of building a report and I'm stuck with one requirement. two of the开发者_如何转开发 columns in the output of my stored procedure are Accomplishments
and UpdateDate
. Now I have to write an expression for the accomplishment field such that it takes the Accomplishments
values corresponding to the latest date in previous month in the UpdateDate
column..
There are multiple Accomplishment
values for every month and all of them are updated at different dates.. please help..
This is what I did:
' SELECT * FROM (
SELECT ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY UpdateDate DESC) AS RN, *
FROM TableName
WHERE UpdateDate BETWEEN DateAdd(mm, DateDiff(mm, 31, GetDate()), 0) AND DateAdd(mm, DateDiff(mm, 0, GetDate()), 0)'
) AS x
WHERE RN = 1
Courtesy Naomi N from MSDN Forums..
精彩评论