[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

raedsawalha

3/28/2007 1:41:00 PM

I have following query i getting following error

Server: Msg 8120, Level 16, State 1, Line 161
Column 'HOME.DESCRIPTION' is invalid in the select list because it is
not contained in either an aggregate function or the GROUP BY clause.

problem occured in DESCRIPTION PART , what could be the right
solution?

SELECT

CASE WHEN (GROUPING(ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)) = 1)
THEN ' '
ELSE
CONVERT(VARCHAR(100),ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION))
END AS 'Building ',
ISNULL(MAX(HOME.ID),HOUSE.ID) AS 'Building_ID'

GROUP BY

ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)
,HOUSE.ID

5 Answers

xyb

3/28/2007 1:45:00 PM

0

On 3?28?, ??9?40?, raedsawa...@gmail.com wrote:
> I have following query i getting following error
>
> Server: Msg 8120, Level 16, State 1, Line 161
> Column 'HOME.DESCRIPTION' is invalid in the select list because it is
> not contained in either an aggregate function or the GROUP BY clause.
>
> problem occured in DESCRIPTION PART , what could be the right
> solution?
>
> SELECT
>
> CASE WHEN (GROUPING(ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)) = 1)
> THEN ' '
> ELSE
> CONVERT(VARCHAR(100),ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION))
> END AS 'Building ',
> ISNULL(MAX(HOME.ID),HOUSE.ID) AS 'Building_ID'
>
> GROUP BY
>
> ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)
> ,HOUSE.ID

add column HOME.DESCRIPTION to group by clause .

raedsawalha

3/28/2007 2:05:00 PM

0

>> GROUP BY
> > ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)
> > ,HOUSE.ID

I already did this ,but getting same issue

i tried this also

>> GROUP BY
> > HOME.DESCRIPTION,
> > HOUSE.ID

getting same problem, any idea please

xyb

3/28/2007 2:10:00 PM

0

On 3?28?, ??10?05?, raedsawa...@gmail.com wrote:
> >> GROUP BY
> > > ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)
> > > ,HOUSE.ID
>
> I already did this ,but getting same issue
>
> i tried this also
>
> >> GROUP BY
> > > HOME.DESCRIPTION,
> > > HOUSE.ID
>
> getting same problem, any idea please

add all columns referenced at case clause to group by clause :)

raedsawalha

3/28/2007 2:12:00 PM

0

The problem i have other group by columns so if i add the missing one
i will get the following

Server: Msg 1027, Level 15, State 1, Line 279
Too many expressions are specified in the GROUP BY clause. The maximum
number is 10 when either CUBE or ROLLUP is specified.


So what I can do in this case :)

Tom Cooper

3/28/2007 5:41:00 PM

0

It is hard to give a complete answer without seeing the entire select
statement and DDL and sample data and the results you want. See
www.aspfaq.com/5006 for instructions on how to do this. That sounds like in
your case that might take some work for you since you are running into that
limit on the number of expressions in the GROUP BY clause, but I think that
is your best hope of getting a complete answer from the group.

If that's not feasible, a way that you could try that often works to solve
this sort of problem is to use a derived table to compute the items so that
you can get rid of the computations in the GROUP BY clause. For example, if
your DDL was

Create Table HOME(ID int, DESCRIPTION varchar(50))
Create Table HOUSE(ID int, DESCRIPTION varchar(50))

Then the following query

SELECT
CASE WHEN (GROUPING(ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)) = 1)
THEN ' '
ELSE
CONVERT(VARCHAR(100),ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION))
END AS 'Building ',
ISNULL(MAX(HOME.ID),HOUSE.ID) AS 'Building_ID'
FROM HOME
CROSS JOIN HOUSE
GROUP BY
ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION)
,HOUSE.ID
WITH ROLLUP

will get your original error Msg 8120, however you could rewrite it as

SELECT
CASE WHEN (GROUPING(Building)) = 1
THEN ' '
ELSE
Building
END AS 'Building ',
ISNULL(MAX(x.HOMEID),x.HOUSEID) AS 'Building_ID'
FROM (SELECT
CONVERT(VARCHAR(100),ISNULL(HOME.DESCRIPTION,HOUSE.DESCRIPTION))
AS 'Building ',
HOUSE.ID As HOUSEID,
HOME.ID As HOMEID
FROM HOME
CROSS JOIN HOUSE) AS x
GROUP BY
x.Building
,x.HOUSEID
WITH ROLLUP

which will not get the error.

Tom

<raedsawalha@gmail.com> wrote in message
news:1175091126.922000.275410@p15g2000hsd.googlegroups.com...
> The problem i have other group by columns so if i add the missing one
> i will get the following
>
> Server: Msg 1027, Level 15, State 1, Line 279
> Too many expressions are specified in the GROUP BY clause. The maximum
> number is 10 when either CUBE or ROLLUP is specified.
>
>
> So what I can do in this case :)
>