SSRS报告查询类型文本 - 必须声明参数错误

时间:2015-10-09 06:53:35

标签: stored-procedures reporting-services sql-server-2008-r2 ssrs-2008-r2

我正在制作SSRS报告。在将------------------------------------------------------------------------------------ You have loaded plyr after dplyr - this is likely to cause problems. If you need functions from both plyr and dplyr, please load plyr first, then dplyr: library(plyr); library(dplyr) ------------------------------------------------------------------------------------ sql代码复制到查询类型dat <- read.table(text="Region Price Alentejano 71 Andalucia 30 Bordeaux 135 Bordeaux 500 Bordeaux 185", header=TRUE) 时,我收到错误。 (查询类型文字的SP代码)

我搜索了google和stackoverflow,但找不到合适的修复解决方案,所以我在这里发帖。

获得以下错误:

Error is something like this

请参阅我知道,此错误是标量变量。忽略上一条消息Store procedure

所以问题是,当我们使用查询类型文本时,我应该如何声明变量。与商店程序一样,它会自动添加到参数中。

此外,查询类型文本不支持set变量,那我该怎么办?

Text

请帮助我,指导我或建议我克服这个问题的最佳解决方案。

注意:我不想使用Incorrect syntax near ')'.。我只想使用Sample query SELECT @ToDate = CAST(MAX(@ToDate) AS DATETIME) + ' 23:59:59.000' SELECT * FROM TableName WHERE EndDate BETWEEN GETDATE() AND @ToDate

3 个答案:

答案 0 :(得分:1)

  

示例查询

     

SELECT @ToDate = CAST(MAX(@ToDate)AS DATETIME)+&#39; 23:59:59.000&#39;
  SELECT * FROM TableName WHERE EndDate BETWEEN GETDATE()AND @ToDate

 declare @ToDate datetime
  --set @ToDate='2015-10-09' this is for example
  SELECT @ToDate = CAST(MAX(@ToDate) AS DATETIME) + ' 23:59:59.000'
  ---select @ToDate
SELECT * FROM TableName WHERE EndDate BETWEEN GETDATE() AND @ToDate

答案 1 :(得分:1)

所以我发现了这个问题,所以当您在报表设计器中编写SQL查询查询类型文本) 时,

1 变量必须声明或设置如下,

body {
    margin: 0;
    padding: 0;
}

.header {
    position: relative;
    z-index: 1;
}

.top {
    background: aqua;
    height: 40px;
    opacity: 0.5;
    position: fixed; /* important – do not change! */
    width: 100%;
    z-index: 5; /* important – do not change! */
}

.bottom {
    background: green;
    height: 40px;
    overflow: hidden; /* important – do not change! */
    position: fixed; /* important – do not change! */
    top: 40px;
    width: 100%;
    z-index: 3; /* important – do not change! */
}

.inside {
    background: red;
    height: 40px;
    position: fixed; /* important – do not change! */
    top: 20px;
    width: 100px;
    z-index: 10; /* doesn't work! */
}

2 同一个表中没有多个选定值。它会抛出错误。

例如:

DECLARE @ToDate DATETIME; -- ended with semicolon ";" SET @ToDate = CAST(MAX(@ToDate) AS DATETIME) + ' 23:59:59.000'; -- ended with semicolon ";"

答案 2 :(得分:0)

您应首先在SSMS中尝试查询,然后在粘贴到SSRS报告之前将其运行到那里。

要在RDL文件中声明变量,语法为:

<QueryParameter Name="@ToDate"> <Value>=Parameters!ToDate.Value</Value> </QueryParameter> <Query> <DataSourceName>xxxyourdatasourcexxx</DataSourceName> <CommandText>SELECT X,Y,Z FROM SCHEMA.TABLENAME WHERE X = @ToDate</CommandText> </Query>