1
select
l.LocationName, l.LocationPrefixCode,
sum(case lt.transid when 1 then lt.Points else 0 end) as TotalEarnpoints,
sum(case lt.transid when 2 then lt.points else 0 end) as TotalRedeempoints,
sum(case lt.transid when 1 then 1 else 0 end) as NoOfBillsEarned,
sum(case lt.transid when 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
ist das einfache SQL? Sie sollten keine doppelten Anführungszeichen in Ihrer Abfrage haben. – Badiparmagi
Verwenden Sie '@' am Anfang Ihrer SQL-Abfragezeichenfolge. Dann können Sie Zeilen ohne Verwendung von '+' oder '' 'umbrechen. –
Welche Bedingung prüfen Sie in der CASE-Klausel? Die Syntax lautet: CASE WHEN THEN ELSE END. Es gibt nichts zwischen" CASE "und" WHEN " –