如何在sql Select子句中添加2个数字?

时间:2013-04-16 14:58:52

标签: sql sql-server tsql sql-server-2012

我有这个问题:

Select 
    Count(DocumentID) 
From 
    Documents d 
Inner Join 
    Accounts a on a.AccountID = d.CreatedByAccountID  
Where 
    a.FeeExempt = 1
    Or
    (Select 
         Case 
             When a.OrganizationTypeID = 1 Or a.OrganizationTypeID = 2 
             Then 0 
             Else EFileFee 
         End 
     From ITypes
     Where ITypeID = d.ITypeID  

    +
    Select 100 --just to test
    ) <= 0

如何编译此查询?基本上我想做2次选择并检查两者的加法是否小于0。但显然目前查询不正确并且无法编译。

1 个答案:

答案 0 :(得分:2)

你想要这个:

. . ..
(select sum(val)
 from ((Select (Case When a.OrganizationTypeID = 1 Or a.OrganizationTypeID = 2 Then 0 Else EFileFee End) as val
        From ITypes
        Where ITypeID = d.ITypeID 
       ) union all
       (Select 100 --just to test
       )
      ) t
 ) <= 0