查询在SSMS中工作但在SSRS中不工作?

时间:2013-11-21 19:19:00

标签: sql reporting-services

我正在使用SQL Server 2012 Visual Studio 2010。

我写了以下查询

SELECT  g.membercode, l.Value as AccountNum, ll.Value as Custodian, MAX(r.positiondate) as PositionDate
  FROM [APXFirm].[AdvApp].[vPortfolioGroupMemberFlattened] g
  LEFT OUTER JOIN [APXFirm].[AdvApp].[vPositionRecon] r
  ON g.MemberID = r.PortfolioID
  LEFT OUTER JOIN [APXFirm].[AdvApp].[vPortfolioBaseCustomLabels] l
  on g.MemberID = l.PortfolioBaseID
    LEFT OUTER JOIN [APXFirm].[AdvApp].[vPortfolioBaseCustomLabels] ll
  on g.MemberID = ll.PortfolioBaseID
  Where g.portfoliogroupcode = 'open'
  and PositionDate is NULL
  and l.label = '$numname'
  and ll.label = '$custdn'
  and ll.Value not in ('mbt', 'whittier')
  group by r.portfoliocode, g.membercode, l.Value, ll.Value
  order by ll.Value, g.MemberCode

在SQL Server Management Studio中,我得到以下所需的结果集

membercode  AccountNum  Custodian   PositionDate
account1    123456      mssb       NULL
account2    78910       mssb       NULL
account3    11121314    mssb       NULL
account4    151617018   mssb       NULL
account5    19202122    mssb       NULL

然而,在SSRS中使用相同的查询我得到以下不受欢迎的结果集,其中帐户名显示在保管人列中,且成员代码为0

Member Code Account Number  Custodian   Position Date   Row Count
0           123456          account1                        1   
0           78910           account2                        2   
0           11121314        account3                        3   
0           151617018       account4                        4   
0           19202122        account5                        5   

知道为什么这个查询在SSMS中起作用而不在SSRS中起作用?

1 个答案:

答案 0 :(得分:1)

我不知道你的结果有何不同。但我建议创建一个sproc并使用它。

另外,您也可以从select中删除PositionDate,因为您有and PositionDate is NULL

条款