【问题标题】:SSRS with Stored Procedure containing multiple count statements具有包含多个计数语句的存储过程的 SSRS
【发布时间】:2017-06-05 14:33:57
【问题描述】:

我有几行查询,其中有多个计数语句。我已经为 select count 语句创建了存储过程,当我在 SSMS 上运行它时它会给出结果,但是当我在 SSRS 中使用存储过程时它只给出第一个查询输出。使用 ssrs 时如何获得其他查询输出?

评论中的代码:

select count(*) as Field1
from #TempTable1;

select count(*) as Field2
from #TempTable2;

select count(distinct ANo) as F3
from #TempTable1;

select count(distinct BNo) as F4
from #TempTable2;

select count(*) as F5
from Table1
where InsertDate >= StartDate
      and InsertDate <= EndDate
      and value1 >= 2
      and TestField = 0;

select count(*) as F6
from Table1
where InsertDate >= StartDate
      and InsertDate <= EndDate
      and value1 >= 2
      and TestField = 1;

select count(*) as F7
from Table1
where InsertDate >= StartDate
      and InsertDate <= EndDate
      and value1 >= 2
      and TestField = 0;

【问题讨论】:

  • 程序代码是什么?您是否将所有计数作为单独的输出?
  • _SELECT Count() As Field1 FROM #TempTable1 SELECT Count() As Field2 FROM #TempTable2 SELECT Count(Distinct ANo) As F3 FROM #TempTable1 SELECT Count(Distinct BNo) As F4 FROM #TempTable2 SELECT count() As F5 FROM Table1 WHERE InsertDate >= StartDate AND InsertDate =2 AND TestField = 0 SELECT count() As F6 FROM Table1 WHERE InsertDate > = StartDate AND InsertDate =2 AND TestField = 1 SELECT count(*) As F7 FROM Table1 WHERE InsertDate >= StartDate AND InsertDate =2 AND TestField = 0 _
  • 我将计数作为单独的输出,但没有声明输出参数,因为我希望代码返回字段和值
  • 您想要 1 行,每个结果的列不同吗?还是多行?
  • 为什么不直接选择 (select count() as Field1 from #TempTable1) 作为 Field1,(select count() as Field2 from #TempTable2) 作为 Field2,(select count (不同的 ANo)作为 F3 来自 #TempTable1)作为 F3 等

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


【解决方案1】:

终于找到答案了

这是我所做的 声明局部变量并在查询中如下使用它们

从 Table1 中选择 @A= count() 从表 2 中选择 @B= count()

选择@A 作为Field1,@B 作为Field2

这会在单行中给出输出。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多