1

在我的查询设计器中,我尝试使用以下查询:

SELECT        Site, LegalConfigNumber, COUNT(*) AS Total
FROM            EPSInfoLive
 iif(@LegalConfigNum  =  0,
WHERE        (InputDate >= @rundate) AND (InputDate <= DATEADD(day, 1, @rundate)),
WHERE        (InputDate >= @rundate) AND (InputDate <= DATEADD(day, 1, @rundate)) AND LegalConfigNumber = @LegalConfigNum)
GROUP BY LegalConfigNumber, Site
ORDER BY Site, LegalConfigNumber

当我尝试对其进行测试时,我收到一条关于 @LegalConfigNum 语法错误的消息。我似乎无法找到那会在哪里。

4

1 回答 1

2

SSRS 查询需要用 SQL 编写。您正在使用“@iif”混合 SQL 和 Visual Basic。SQL 支持 CASE 语句而不是 IIF。但是你不需要这个来展示你所展示的东西。下面的陈述在逻辑上应该是等价的:

SELECT
   Site,
   LegalConfigNumber,
   COUNT(*) AS Total
FROM
   EPSInfoLive
WHERE
   (InputDate >= @rundate) AND (InputDate <= DATEADD(day, 1, @rundate))
   AND (LegalConfigNumber = @LegalConfigNum OR @LegalConfigNum  =  0)
GROUP BY LegalConfigNumber, Site
ORDER BY Site, LegalConfigNumber
于 2012-09-24T18:32:29.877 回答