嗨,我有以下SQL可以获取数据。因此,我尝试使用参数仅显示基于一周的数据。当我运行查询时,将打开“定义查询参数”对话框,但是当我单击“确定”后,出现错误提示: 执行查询时发生错误。 ';'附近的语法不正确。 (Microsoft SQL Server报表生成器)
如果我没有声明参数,那么它将给我一个错误,提示我必须声明参数。如果选择参数的数据类型,则会运行查询,但不会出现“定义参数”对话框。
我不确定我在这里做错了什么。我已经查看了所有可用的内容,但似乎无法弄清楚。
Declare @Week;
WITH Day_Level
AS
(
SELECT Microsoft_VSTS_Scheduling_CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate,
Microsoft_VSTS_Scheduling_RemainingWork,
x.[[WorkingItem]].[System_Id]]],
[Date].[Date] AS '[Date].[Date]',
[Date].[WeekOfYear] AS '[Date].[WeekOfYear]',
[Date].[WeekString] AS '[Date].[WeekString]',
CONCAT(LEFT(DATENAME(WEEKDAY, [Date].[Date]),3),'.') AS '[Date].[Weekday]',
[Date].[Year] AS '[Date].[Year]',
[Date].[YearString] AS '[Date].[YearString]'
FROM
(
select
Microsoft_VSTS_Scheduling_CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate,
Microsoft_VSTS_Scheduling_RemainingWork,
[Item].[System_Id] AS '[WorkingItem].[System_Id]',
[Date].[Date] AS '[Date].[Date]',
ROW_NUMBER() OVER (PARTITION BY [Item].[System_Id], [Date].[Date] ORDER BY [Date].[Date], [Item].[System_Rev] DESC, [Fact].[LastUpdatedDateTime] DESC) AS RN
from dbo.FactWorkItemHistory Fact
inner join dbo.DimWorkItem Item
on fact.WorkItemSK = item.WorkItemSK
and fact.TeamProjectSK = item.TeamProjectSK
inner join dbo.DimDate [date]
on fact.DateSK = [date].DateSK
inner join dbo.DimTeamProject Project
on project.ProjectNodeSK = fact.TeamProjectSK
inner join dbo.DimPerson Person
on person.PersonSK = item.System_AssignedTo__PersonSK
inner join DimIteration Iteration
on iteration.IterationSK = item.IterationSK
where fact.RevisionCount is not null AND
[Project].[ProjectPath] = '\B2B_CRM\PhProduct'
) AS x
inner join dbo.DimDate [date]
on x.[[Date]].[Date]]] = [date].[Date]
WHERE x.RN = 1
AND Microsoft_VSTS_Scheduling_CompletedWork IS NOT NULL
),
Attributes
AS
(
select
[Fact].[Microsoft_VSTS_Scheduling_CompletedWork] AS '[WorkItemFact].[Microsoft_VSTS_Scheduling_CompletedWork]',
[Fact].[Sca_Common_CompletedWorkTotal] AS '[WorkItemFact].[Sca_Common_CompletedWorkTotal]',
[Item].[Sca_Common_WBS] AS '[WorkItem].[Sca_Common_WBS]',
LEFT([Item].[Sca_Common_WBS], 18) AS '[WorkItem].[Sca_Common_WBS_Short]',
[Item].[Sca_Common_WBSType] AS '[WorkItem].[Sca_Common_WBSType]',
[Item].[System_Id] AS '[WorkItem].[System_Id]',
[Person].[Name] AS '[AssignedTo].[Name]',
IIF (YEAR([Item].[System_RevisedDate]) = 9999, 'True', 'False') AS '[WorkItem].[LastRevision]',
[Iteration].[IterationPath] AS '[WorkItem].[Iteration]'
from dbo.FactWorkItemHistory Fact
inner join dbo.DimWorkItem Item
on fact.WorkItemSK = item.WorkItemSK
and fact.TeamProjectSK = item.TeamProjectSK
inner join dbo.DimTeamProject Project
on project.ProjectNodeSK = fact.TeamProjectSK
inner join dbo.DimPerson Person
on person.PersonSK = item.System_AssignedTo__PersonSK
inner join DimIteration Iteration
on iteration.IterationSK = item.IterationSK
where fact.RevisionCount is not null AND
[Project].[ProjectPath] = '\B2B_CRM\PhProduct'
and YEAR([Item].[System_RevisedDate]) = 9999
),
Final
AS
(
SELECT
ISNULL(Microsoft_VSTS_Scheduling_CompletedWork - lag(Microsoft_VSTS_Scheduling_CompletedWork) over (PARTITION BY Day_Level.[[WorkingItem]].[System_Id]]] order by Day_Level.[[Date]].[Date]]]),Microsoft_VSTS_Scheduling_CompletedWork)
AS CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate AS OriginalWork,
Microsoft_VSTS_Scheduling_RemainingWork AS RemainingWork,
Day_Level.[[Date]].[WeekOfYear]]] AS WeekNumber,
*
FROM Day_Level
INNER JOIN Attributes
ON Day_Level.[[WorkingItem]].[System_Id]]] = Attributes.[[WorkItem]].[System_Id]]]
)
Select *
FROM Final
where WeekNumber = (@Week)
答案 0 :(得分:0)
使用CTE,在SSRS中沿着
的行创建一个数据集Select distinct WeekNumber
FROM Final
将该数据集分配给您的(@ Week)参数(该参数应显示在“报表生成器”(或其他用于生成报表的内容)中)
可以使用相同的数据集设置默认值,并且您可能还希望允许多个值。
在这种情况下,我的数据集称为dsOfferingType,但数据是从结果数据集中获取的。
这有意义吗?
答案 1 :(得分:0)
@JonTout我明白你的意思,但这不是我想要的。因此,我将查询最小化到以下内容,您可以看到我在结尾处放了一个参数(变量),当我使用此参数进行查询时,它会打开一个dialog box。
select
Microsoft_VSTS_Scheduling_CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate,
Microsoft_VSTS_Scheduling_RemainingWork,
[Item].[System_Id] AS '[WorkingItem].[System_Id]',
[Date].[Date] AS '[Date].[Date]',
ROW_NUMBER() OVER (PARTITION BY [Item].[System_Id], [Date].[Date] ORDER BY [Date].[Date], [Item].[System_Rev] DESC, [Fact].[LastUpdatedDateTime] DESC) AS RN
from dbo.FactWorkItemHistory Fact
inner join dbo.DimWorkItem Item
on fact.WorkItemSK = item.WorkItemSK
and fact.TeamProjectSK = item.TeamProjectSK
inner join dbo.DimDate [date]
on fact.DateSK = [date].DateSK
inner join dbo.DimTeamProject Project
on project.ProjectNodeSK = fact.TeamProjectSK
inner join dbo.DimPerson Person
on person.PersonSK = item.System_AssignedTo__PersonSK
inner join DimIteration Iteration
on iteration.IterationSK = item.IterationSK
where fact.RevisionCount is not null AND
[Project].[ProjectPath] = '\B2B_CRM\PhProduct'
AND Microsoft_VSTS_Scheduling_CompletedWork IS NOT NULL
AND Microsoft_VSTS_Scheduling_CompletedWork = @Something
现在,我像这样添加第二部分,然后它给了我this error。不知道是什么导致它像这样。
SELECT Microsoft_VSTS_Scheduling_CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate,
Microsoft_VSTS_Scheduling_RemainingWork,
x.[[WorkingItem]].[System_Id]]],
[Date].[Date] AS '[Date].[Date]',
[Date].[WeekOfYear] AS '[Date].[WeekOfYear]',
[Date].[WeekString] AS '[Date].[WeekString]',
CONCAT(LEFT(DATENAME(WEEKDAY, [Date].[Date]),3),'.') AS '[Date].[Weekday]',
[Date].[Year] AS '[Date].[Year]',
[Date].[YearString] AS '[Date].[YearString]'
FROM
(
select
Microsoft_VSTS_Scheduling_CompletedWork,
Microsoft_VSTS_Scheduling_OriginalEstimate,
Microsoft_VSTS_Scheduling_RemainingWork,
[Item].[System_Id] AS '[WorkingItem].[System_Id]',
[Date].[Date] AS '[Date].[Date]',
ROW_NUMBER() OVER (PARTITION BY [Item].[System_Id], [Date].[Date] ORDER BY [Date].[Date], [Item].[System_Rev] DESC, [Fact].[LastUpdatedDateTime] DESC) AS RN
from dbo.FactWorkItemHistory Fact
inner join dbo.DimWorkItem Item
on fact.WorkItemSK = item.WorkItemSK
and fact.TeamProjectSK = item.TeamProjectSK
inner join dbo.DimDate [date]
on fact.DateSK = [date].DateSK
inner join dbo.DimTeamProject Project
on project.ProjectNodeSK = fact.TeamProjectSK
inner join dbo.DimPerson Person
on person.PersonSK = item.System_AssignedTo__PersonSK
inner join DimIteration Iteration
on iteration.IterationSK = item.IterationSK
where fact.RevisionCount is not null AND
[Project].[ProjectPath] = '\B2B_CRM\PhProduct'
) AS x
inner join dbo.DimDate [date]
on x.[[Date]].[Date]]] = [date].[Date]
WHERE x.RN = 1
AND Microsoft_VSTS_Scheduling_CompletedWork IS NOT NULL
AND Microsoft_VSTS_Scheduling_CompletedWork = @Something