Syntax error I can't understand

  • Server: Msg 156, Level 15, State 1, Line 94

    Incorrect syntax near the keyword 'GROUP'.

    Line 94 is the Group keyword line from the SQL below:

    INSERT INTO #PDATemp_ReportData

    SELECT

    'Registration' AS RType,

    Type AS [NAME],

    JanAmt = Sum(CASE WHEN Month(dateentered) = 1 THEN cast(cost AS money) ELSE 0 END),

    FebAmt = Sum(CASE WHEN Month(dateentered) = 2 THEN cast(cost AS money) ELSE 0 END),

    MarAmt = Sum(CASE WHEN Month(dateentered) = 3 THEN cast(cost AS money) ELSE 0 END),

    AprAmt = Sum(CASE WHEN Month(dateentered) = 4 THEN cast(cost AS money) ELSE 0 END),

    MayAmt = Sum(CASE WHEN Month(dateentered) = 5 THEN cast(cost AS money) ELSE 0 END),

    JunAmt = Sum(CASE WHEN Month(dateentered) = 6 THEN cast(cost AS money) ELSE 0 END),

    JulAmt = Sum(CASE WHEN Month(dateentered) = 7 THEN cast(cost AS money) ELSE 0 END),

    Augamt = Sum(CASE WHEN Month(dateentered) = 8 THEN cast(cost AS money) ELSE 0 END),

    Sepamt = Sum(CASE WHEN Month(dateentered) = 9 THEN cast(cost AS money) ELSE 0 END),

    Octamt = Sum(CASE WHEN Month(dateentered) = 10 THEN cast(cost AS money) ELSE 0 END),

    Novamt = Sum(CASE WHEN Month(dateentered) = 11 THEN cast(cost AS money) ELSE 0 END),

    DecAmt = Sum(CASE WHEN Month(dateentered) = 12 THEN cast(cost AS money) ELSE 0 END)

    FROM

    #PDATemp_Detailstable

    WHERE

    (((Type = 'Registration' AND MeetingType = 'Programs & Meetings' AND (Item NOT like '%Institute%' AND Item NOT like '%Track%')) OR

    (Type = 'Discount' AND Item like '%UBS%') OR

    (Type = 'Registration' AND MeetingType = 'Web Seminars') OR

    (Type = 'Discount' AND Item like '%Registration%') OR

    (Type = 'Discount' AND MeetingType = 'Programs & Meetings' AND Item NOT like '%Registration%') OR

    (Type = 'Credit' AND MeetingType = 'Programs & Meetings') OR

    (Type = 'Refund' AND MeetingType = 'Programs & Meetings' AND Item NOT LIKE '%Course%') OR

    (Type = 'Credit' AND MeetingType = 'Web Seminars') OR

    (Type = 'Refund' AND MeetingType = 'Web Seminars')) AND

    dateentered >= @startingdate AND

    dateentered <= @endingdate AND

    VOID = 0 AND

    MeetingTYPE <> 'Training Courses'

    GROUP BY Type

  • there is an extra opening bracket not closed....

  • Hi,

    There is a messing one parenthesis

    SELECT

    'Registration' AS RType,

    Type AS [NAME],

    JanAmt = Sum(CASE WHEN Month(dateentered) = 1 THEN cast(cost AS money) ELSE 0 END),

    FebAmt = Sum(CASE WHEN Month(dateentered) = 2 THEN cast(cost AS money) ELSE 0 END),

    MarAmt = Sum(CASE WHEN Month(dateentered) = 3 THEN cast(cost AS money) ELSE 0 END),

    AprAmt = Sum(CASE WHEN Month(dateentered) = 4 THEN cast(cost AS money) ELSE 0 END),

    MayAmt = Sum(CASE WHEN Month(dateentered) = 5 THEN cast(cost AS money) ELSE 0 END),

    JunAmt = Sum(CASE WHEN Month(dateentered) = 6 THEN cast(cost AS money) ELSE 0 END),

    JulAmt = Sum(CASE WHEN Month(dateentered) = 7 THEN cast(cost AS money) ELSE 0 END),

    Augamt = Sum(CASE WHEN Month(dateentered) = 8 THEN cast(cost AS money) ELSE 0 END),

    Sepamt = Sum(CASE WHEN Month(dateentered) = 9 THEN cast(cost AS money) ELSE 0 END),

    Octamt = Sum(CASE WHEN Month(dateentered) = 10 THEN cast(cost AS money) ELSE 0 END),

    Novamt = Sum(CASE WHEN Month(dateentered) = 11 THEN cast(cost AS money) ELSE 0 END),

    DecAmt = Sum(CASE WHEN Month(dateentered) = 12 THEN cast(cost AS money) ELSE 0 END)

    FROM

    #PDATemp_Detailstable

    WHERE

    (

    ((Type = 'Registration' AND MeetingType = 'Programs & Meetings' AND (Item NOT like '%Institute%' AND Item NOT like '%Track%')) OR

    (Type = 'Discount' AND Item like '%UBS%') OR (Type = 'Registration' AND MeetingType = 'Web Seminars') OR

    (Type = 'Discount' AND Item like '%Registration%') OR (Type = 'Discount' AND MeetingType = 'Programs & Meetings' AND Item NOT like '%Registration%') OR

    (Type = 'Credit' AND MeetingType = 'Programs & Meetings') OR (Type = 'Refund' AND MeetingType = 'Programs & Meetings' AND Item NOT LIKE '%Course%') OR

    (Type = 'Credit' AND MeetingType = 'Web Seminars') OR (Type = 'Refund' AND MeetingType = 'Web Seminars')

    )) AND

    (dateentered >= @startingdate AND

    dateentered 'Training Courses')

    GROUP BY Type

    Regards,

    Ahmed

  • Sory or an extra one like Rajesh Patavardhan said

  • Yes thats what it was! I just looked and looked and could not see that!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply