工作SQL查询时出现C#错误 - 变量名已经声明

时间:2016-07-15 17:09:18

标签: sql sql-server symantec altiris

enter image description here

以下查询在SQL Management Studio和Altiris中运行正常。当我们尝试将代码添加到使用C#编写的自定义报告工具时,我们会收到上述错误。

Declare @AcroPro        int
Declare @AcroStan       int

set @AcroPro = (select COUNT(distinct guid) from vAdobe_Acrobat_Pro where [Display Name] like '%Professional')
set @AcroStan = (select COUNT(distinct guid) from vAdobe_Acrobat_Stan where [Display Name] like '%Standard')

select distinct v2.name 'Software Product', t2.[Purchased Licenses], CASE 

      When t2._resourceguid = '8708D8B8-51A0-4386-B4A1-620CC63DEF0D'
      Then @AcroPro
      When t2._resourceguid = '37997FB9-9936-42CF-A34C-D68214C353CF'
      Then @AcroStan
      End [Active Licenses], CASE 

      When t2._resourceguid = '8708D8B8-51A0-4386-B4A1-620CC63DEF0D'
      Then t2.[purchased licenses] - @AcroPro
      When t2._resourceguid = '37997FB9-9936-42CF-A34C-D68214C353CF'
      Then t2.[purchased licenses] -@AcroStan
      End [Compliance] from vComputer v1

inner join Inv_SoftwareProduct_InstallationInfo t1 on v1.Guid = t1._computerResourceGuid
inner join Inv_SoftwareProduct_ComplianceInfo t2 on t1._ResourceGuid = t2._ResourceGuid
inner join vSoftwareProduct v2 on t2._ResourceGuid = v2.guid

where v2.name in ('Adobe Acrobat Professional', 'Adobe Acrobat Standard')

and v1.IsManaged = '1'

1 个答案:

答案 0 :(得分:2)

您的报告工具可能在同一查询批次中发送相同的一组SQL命令两次,在这种情况下,这些变量将被重新声明。