这个查询的错误是什么?错误:关键字“case”附近的语法不正确

时间:2017-12-11 11:38:24

标签: sql sql-server

console.log(this.props)

1 个答案:

答案 0 :(得分:0)

select 
l.LocationName, l.LocationPrefixCode, 
sum(case when lt.transid=1 then lt.Points else 0 end) as TotalEarnpoints, 
sum(case when lt.transid=2 then lt.points else 0 end) as TotalRedeempoints, 
sum(case when lt.transid=1 then 1 else 0 end) as NoOfBillsEarned, 
sum(case when lt.transid=2 then 1 else 0 end) as NoOfBillsRedeemed
from 
    InvLoyaltyTransaction lt 
inner join
    dbo.Location l ON lt.LocationID = l.LocationID 
where 
    cast(DocumentDate as date) between convert(date, '" + fromDate + "', 103)  
                                   and convert(date, '" + toDate + "', 103) 
    and CardType in (select CardMasterID 
                     from CrmReportCondition) 
    and lt.LocationID != 1
group by
    l.LocationName, l.LocationPrefixCode 
order by 
    l.LocationName