Stored procedure syntax help

  • I keep getting a syntax error near ')' for the following - can anyone help please??

    CREATE PROCEDURE sp_getInfo

    AS

    --Begin

    Select Office, tab, title,

    round(SUM(curno),2) as CurNo,

    round(sum(prevno),2) as PrevNo, TabOrder, SortOrder

    from

    (select Office1, Tab, title,

    (case isyear when 2005 then (No*Percent1) else 0 end) AS CurNo,

    (case isyear when 2004 then (No*Percent2) else 0 end) AS PrevNo,

    TabOrder, SortOrder from vwData A

    where Mnth between 1 and  @Month  and IsYear in (@Year,  @Year-1) and Office1 = @office )

    --end

  • When you use a derived table you need to give it a name or alias.

    CREATE PROCEDURE sp_getInfo

    AS

    --Begin

    Select Office, tab, title,

    round(SUM(curno),2) as CurNo,

    round(sum(prevno),2) as PrevNo, TabOrder, SortOrder

    from

    (select Office1, Tab, title,

    (case isyear when 2005 then (No*Percent1) else 0 end) AS CurNo,

    (case isyear when 2004 then (No*Percent2) else 0 end) AS PrevNo,

    TabOrder, SortOrder from vwData A

    where Mnth between 1 and  @Month  and IsYear in (@Year,  @Year-1) and Office1 = @office ) AS MyDerivedTable

  • THANK YOU!

  • One IMPORTANT ITEM.

    NEVER name your stored-procedures sp_ ....  This will cause performance problems and you will start getting confused as to what did I create v. Microsoft create.



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

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

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