urgent@@Help in Modify the query

  • Can any one help with below query. i am getting error saying that

    Msg 8120, Level 16, State 1, Line 1

    Column 'AEG_DB.dbo.MRO_TBL_EMCData.Application ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    select [September 2012 Billing File] = CASE WHEN T2.[Application ID] IS NOT NULL AND T2.[ServerName]

    IS NOT NULL AND Sum([Billed This Month]) <> 0 THEN 'Y' ELSE 'N' END

    FROM [AEG_DB].[dbo].[TBL_Work] T1

    LEFT JOIN [TBL_Data] T2 ON (T1.[Application ID] = T2.[Application ID] AND T1.[ServerName] = T2.[ServerName])

    WHERE T2.[Data Period] = 'September 2012'

  • Check the view [TBL_Data]

  • Try this

    SELECT [September 2012 Billing File] =

    CASE

    WHEN T2.[Application ID] IS NOT NULL

    AND T2.[ServerName] IS NOT NULL

    AND SUM([Billed This Month]) <> 0

    THEN 'Y'

    ELSE 'N'

    END

    FROM[AEG_DB].[dbo].[TBL_Work] T1

    LEFT JOIN[TBL_Data] T2

    ON (T1.[Application ID] = T2.[Application ID]

    AND T1.[ServerName] = T2.[ServerName])

    WHERET2.[Data Period] = 'September 2012'

    GROUP BYT2.[Application ID],

    T2.[ServerName];

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

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

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