如果您选择开始日期和结束日期,我需要在几周内显示细分数据。我必须在堆积柱形图中显示。我试图显示值,如果您选择上个月我需要按周显示它,例如
week user name total approved first approved last aprovedDate totalitemsAdded
----- --------- -------------- -------------- ---------------- ---------------
week1 XYZ 3 10/01/2012 10/05/2012 5
week2 XYZ 5 etc etc etc
week3
以下是我现在获得的代码和结果。
当前结果
UserName TotalApproved FirstApprovedDate LastApprovedDate TotalItemsAdded
-------- ------------- ----------------------- ----------------------- ---------------
XYZ 9 2011-11-19 16:56:49.960 2011-11-19 18:18:20.783 2
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '10/1/2012 '
SET @EndDate = '10/31/2012'
;with Items as(
SELECT
UserName = Profile.Description,
TotalItems = COUNT(TransactionID),
FirstAddedDate = MIN(UTCDate),
LastAddedDate = MAX(UTCDate)
FROM Transactiondatabase.dbo.transaction
JOIN Biography.dbo.Profile ON transaction.ProfileId = Profile.ProfileID
WHERE
Data like '%ItemAdded%'
AND UTCDate BETWEEN @StartDate AND DATEADD(dd,1,@EndDate)
GROUP BY
Profile.Description
)
,
Approved as
(
SELECT
UserName = Profile.Description,
TotalApproved = COUNT(TransactionID),
FirstApprovedDate = MIN(UTCDate),--Demo
LastApprovedDate = MAX(UTCDate)
FROM Transactiondatabase..transaction
JOIN Biography.dbo.Profile ON transaction.ProfileId = Profile.ProfileID
WHERE
Data like '%Approved%'
AND UTCDate BETWEEN @StartDate AND DATEADD(dd,1,@EndDate)
GROUP BY
Profile.Description
)
Select Distinct Approved.*, TotalItemssAdded = sum(distinct Items.TotalItems)
from Items, Approved
Group by Approved.UserName, Approved.FirstApprovedDate, Approved.LastApprovedDate, Approved.TotalApproved
using ssrs 2005
答案 0 :(得分:0)
你可能会发现:
DATEPART( WEEK, UTCDate )
有帮助的。如:
SELECT FirstApprovedWeek = DATEPART( WEEK, UTCDATE ) FROM table
有关详细信息和使用选项,请参阅MSDN - DATEPART (Transact-SQL)。