SSRS查询获取标量变量错误,而不是在Visual Studio中使用参数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSRS查询获取标量变量错误,而不是在Visual Studio中使用参数相关的知识,希望对你有一定的参考价值。
我在SSRS中使用报告中未使用已声明的参数时遇到麻烦。在报告中,我已经有两个查询,它们都使用@Period来确定用户请求的月份。但是,在第三份报告中,它不断出现标量变量错误,并希望我声明@Period,当然,除非我指定int值会带来完全不正确的数字,因为它是所有值的总和而不是设定的时间。
我已经遍历了代码,甚至从工作代码中复制了粘贴@Period的代码,以查看是否存在隐藏的空间或某些阻止其使用正确参数的东西,但仍然看不到它。下面是Visual Studio中报告数据窗口的屏幕截图以及我正在使用的代码。我只是不明白为什么它不能使用@Period。
Declare @Year As int
--Declare @Period As int = 9
--Sets up the year for this financial year
If @Period Between 5 and 12
Begin
Set @Year = Year(Getdate()) + 1
End
Else
Set @Year = YEAR(Getdate())
--Sets the Declared Period to the correct number for Clients
if @Period = 5
Begin
Set @Period = 1
End
ELSE if @Period = 6
Begin
Set @Period = 2
End
Else if @Period = 7
Begin
Set @Period = 3
End
Else if @Period = 8
Begin
Set @Period = 4
End
Else if @Period = 9
Begin
Set @Period = 5
End
Else if @Period = 10
Begin
Set @Period = 6
End
Else if @Period = 11
Begin
Set @Period = 7
End
Else if @Period = 12
Begin
Set @Period = 8
End
Else if @Period = 1
Begin
Set @Period = 9
End
Else if @Period = 2
Begin
Set @Period = 10
End
Else if @Period = 3
Begin
Set @Period = 11
End
Else
Set @Period = 12
--This Sorts all the clients into their sectors
SELECT A.GROUP_NAME,B.CLIENT_DIWOR
INTO #TMPCLIENT
FROM CLIENT_GROUP A
JOIN CLIENT_GRP_MEMBER B on A.DIWOR = B.CLIENT_GRP_DIWOR
WHERE GROUP_TYPE = 'THEME'
GROUP BY A.GROUP_NAME,B.CLIENT_DIWOR
--This sets the figures according to Current year and period range
SELECT A.MATTER_ALPHA_NAME,B.FEES_PRD As Fees,A.CLIENT_DIWOR,D.GROUP_NAME
INTO #Fees
FROM MATTER A
JOIN ON_MAT_FE_PERF B on A.MATTER_DIWOR = B.MATTER_DIWOR
JOIN PM_YEAR C on B.FINYEARDIWOR = C.DIWOR
LEFT JOIN #TMPCLIENT D on D.CLIENT_DIWOR = A.CLIENT_DIWOR
WHERE C.YEARDESC = @Year and B.PERIOD between 1 and @Period and B.FEES_PRD <> 0 and D.GROUP_NAME
is
not NULL
order by MATTER_ALPHA_NAME
--This sets Previous year and period
Set @Year = SUM(@Year-1)
SELECT A.MATTER_ALPHA_NAME,B.FEES_PRD As Fees,A.CLIENT_DIWOR,D.GROUP_NAME
INTO #PFees
FROM MATTER A
JOIN ON_MAT_FE_PERF B on A.MATTER_DIWOR = B.MATTER_DIWOR
JOIN PM_YEAR C on B.FINYEARDIWOR = C.DIWOR
LEFT JOIN #TMPCLIENT D on D.CLIENT_DIWOR = A.CLIENT_DIWOR
WHERE C.YEARDESC = @Year and B.PERIOD between 1 and @Period and B.FEES_PRD <> 0 and D.GROUP_NAME
is not NULL
order by MATTER_ALPHA_NAME
Select TOP 20
MATTER_ALPHA_NAME,SUM(Fees) As Fees,GROUP_NAME
Into #Charities
FROM #Fees
WHERE GROUP_NAME = 'Charities (Sector)'
GROUP By MATTER_ALPHA_NAME,GROUP_NAME
ORDER BY Fees Desc
Select TOP 20
MATTER_ALPHA_NAME,SUM(Fees) As Fees,GROUP_NAME
Into #PCharities
FROM #PFees
WHERE GROUP_NAME = 'Charities (Sector)'
GROUP By MATTER_ALPHA_NAME,GROUP_NAME
ORDER BY Fees Desc
SELECT ROUND(SUM(Fees),-3) As Fees
Into #TmpCharC
FROM #Charities
SELECT ROUND(SUM(Fees),-3) As Fees
Into #TmpCharP
FROM #PCharities
Create Table #Main (Charity int,PCharity int)
insert into #Main (Charity,PCharity)
Select A.Fees,B.Fees
from #TmpCharC A
CROSS JOIN #TmpCharP B
Select * From #Main
答案
因此,在进一步挖掘之后,我发现了问题。
内部数据集属性和参数中,由于某种随机原因,未包含根据映像指定的参数名称。添加此操作可解决此问题。
感谢Zoher Peled提供了有关模块化算术技巧的提示
以上是关于SSRS查询获取标量变量错误,而不是在Visual Studio中使用参数的主要内容,如果未能解决你的问题,请参考以下文章
使用 ODBC 连接到 SQL SERVER 时,s-s-rS 错误必须声明标量变量
Grafana/InfluxDB:查询在面板中工作,而不是在变量中
如何让Visual Studio 2008编辑SSRS 2005报表项目没有安装SQL Business Intelligence Development Studio 2005?