SQLTeam.com | Weblogs | Forums

Incorrect Syntax creating stored procedure


#1

Getting incorrect syntax near keyword group trying to create this stored procedure.

CREATE PROCEDURE QIVSALESBYREP
-- Add the parameters for the stored procedure here
@MONTH CHAR(2),
@YEAR CHAR(4)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here

select cus_no,c.cmp_name, user_def_fld_3,
ISNULL(SUM(CASE WHEN year(billed_dt) = @year - 1 THEN sls_amt END), 0) AS LYSales,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) = @month THEN sls_amt END), 0) AS MTDSales,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN sls_amt END), 0) AS YTDLY,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year - 1 and month(billed_dt) <= @month THEN cost_amt END), 0) AS YTDLYCosts,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year - 1 and month(billed_dt) <= @month THEN sls_amt END), 0)- ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year - 1 and month(billed_dt) <= @month THEN cost_amt END), 0) as MarginLY,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN sls_amt END), 0) AS YTD,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN cost_amt END), 0) AS YTDCosts,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN sls_amt END), 0) - ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN cost_amt END), 0) AS MarginCY,
ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year - 1 and month(billed_dt) <= @month THEN sls_amt END), 0) - ISNULL(SUM(CASE WHEN YEAR(billed_dt) = @year and month(billed_dt) <= @month THEN sls_amt END), 0) AS DIFF
from dbo.OElineusecd l join cicmpy c on l.cus_no = c.debcode
where @month = MONTH(billed_dt) and @year = (YEAR(billed_dt)
group by c.cmp_name, cus_no , user_def_fld_3
order by cmp_name
END
GO


#2

Never mind.

Just figured out I left out a ) after (year(billed_dt))