Hi,
This script is working until I added @CustomerCode. What is the syntax error?
Thanks,
Noel
DECLARE @Start INT
DECLARE @End INT
DECLARE @CustomerCode nVarChar(15)
SELECT @Start = TF.[Year] FROM OACP TF WHERE TF.[Year] = [%0]
SELECT @End = TF.[Year] FROM OACP TF WHERE TF.[Year] = [%1]
SELECT @CustomerCode = TC.[CardCode] FROM OCRD TC WHERE TC.[CardCode] = [%2]
SELECT T0.CardCode
,T0.CardName
,T0.ItemCode
,T1.ItemName
,T0.Year
,SUM(T0.Jan) AS Jan
,SUM(T0.Feb) AS Feb
,SUM(T0.Mar) AS Mar
,SUM(T0.Apr) AS Apr
,SUM(T0.May) AS May
,SUM(T0.Jun) AS Jun
,SUM(T0.Jul) AS Jul
,SUM(T0.Aug) AS Aug
,SUM(T0.Sep) AS Sep
,SUM(T0.Oct) AS Oct
,SUM(T0.Nov) AS Nov
,SUM(T0.Dec) AS Dec
FROM TWC_FGMonthlySales T0
INNER JOIN OITM T1 ON T1.ItemCode = T0.ItemCode
WHERE (T0.Year = @Start
OR T0.Year = @End)
AND T0.CardCode = @CustomerCode
GROUP BY T0.CardCode
,T0.CardName
,T0.ItemCode
, T1.ItemName
, T0.Year
ORDER BY T0.CardCode
,T0.ItemCode
,T0.Year Desc