Home All Groups Group Topic Archive Search About

Problem with GROUP BY/COMPUTE : error message 8120

Author
20 Oct 2005 3:42 PM
Laurent CLAUDEL
Hi,

I have this query ( it is Ok with Sybase SQLServer)

select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
from HREH3M
group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
compute sum(count(NVOI)) by CPST,NVOI,datepart(yy,DPSTVOI)


I want to migrate it under MS SQLServer 2000, but I have this error message
:
Serveur : Msg 8120, Niveau 16, État 1, Ligne 1
Column 'HREH3M.DPSTVOI' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.

If I delete the last line, the query is Ok :
select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
from HREH3M
group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)

The problem is with COMPUTE claude, but I can't understand why.

please help me to solve this.

thanks in advance

regards

    Laurent

Author
20 Oct 2005 3:55 PM
Enric
What kind of error or warning appears when you drop that line? Apparently
syntax for COMPUTE is fine.

Show quote
"Laurent CLAUDEL" wrote:

> Hi,
>
> I have this query ( it is Ok with Sybase SQLServer)
>
> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
> from HREH3M
> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
> compute sum(count(NVOI)) by CPST,NVOI,datepart(yy,DPSTVOI)
>
>
> I want to migrate it under MS SQLServer 2000, but I have this error message
> :
> Serveur : Msg 8120, Niveau 16, État 1, Ligne 1
> Column 'HREH3M.DPSTVOI' is invalid in the select list because it is not
> contained in either an aggregate function or the GROUP BY clause.
>
> If I delete the last line, the query is Ok :
> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
> from HREH3M
> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>
> The problem is with COMPUTE claude, but I can't understand why.
>
> please help me to solve this.
>
> thanks in advance
>
> regards
>
>     Laurent
>
>
>
Author
20 Oct 2005 3:59 PM
Laurent CLAUDEL
if I drop the last line (COMPUTE), there is no more error.

"Enric" <En***@discussions.microsoft.com> a écrit dans le message de news:
B27D7A22-9880-4A31-9335-D0C77C2DE***@microsoft.com...
Show quote
> What kind of error or warning appears when you drop that line? Apparently
> syntax for COMPUTE is fine.
>
> "Laurent CLAUDEL" wrote:
>
>> Hi,
>>
>> I have this query ( it is Ok with Sybase SQLServer)
>>
>> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
>> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
>> from HREH3M
>> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>> compute sum(count(NVOI)) by CPST,NVOI,datepart(yy,DPSTVOI)
>>
>>
>> I want to migrate it under MS SQLServer 2000, but I have this error
>> message
>> :
>> Serveur : Msg 8120, Niveau 16, État 1, Ligne 1
>> Column 'HREH3M.DPSTVOI' is invalid in the select list because it is not
>> contained in either an aggregate function or the GROUP BY clause.
>>
>> If I delete the last line, the query is Ok :
>> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
>> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
>> from HREH3M
>> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>>
>> The problem is with COMPUTE claude, but I can't understand why.
>>
>> please help me to solve this.
>>
>> thanks in advance
>>
>> regards
>>
>>     Laurent
>>
>>
>>
Author
20 Oct 2005 4:49 PM
Laurent CLAUDEL
But I want a sum by Year, so i have to keep the COMPUTE clause

"Laurent CLAUDEL" <laurent.clau***@steria.com> a écrit dans le message de
news: OhOqg8Y1FHA.1***@TK2MSFTNGP14.phx.gbl...
Show quote
> if I drop the last line (COMPUTE), there is no more error.
>
> "Enric" <En***@discussions.microsoft.com> a écrit dans le message de news:
> B27D7A22-9880-4A31-9335-D0C77C2DE***@microsoft.com...
>> What kind of error or warning appears when you drop that line? Apparently
>> syntax for COMPUTE is fine.
>>
>> "Laurent CLAUDEL" wrote:
>>
>>> Hi,
>>>
>>> I have this query ( it is Ok with Sybase SQLServer)
>>>
>>> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
>>> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
>>> from HREH3M
>>> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>>> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>>> compute sum(count(NVOI)) by CPST,NVOI,datepart(yy,DPSTVOI)
>>>
>>>
>>> I want to migrate it under MS SQLServer 2000, but I have this error
>>> message
>>> :
>>> Serveur : Msg 8120, Niveau 16, État 1, Ligne 1
>>> Column 'HREH3M.DPSTVOI' is invalid in the select list because it is not
>>> contained in either an aggregate function or the GROUP BY clause.
>>>
>>> If I delete the last line, the query is Ok :
>>> select  'Voie'=NVOI,'Mois'=datepart(mm,DPSTVOI)
>>> ,'Année'=datepart(yy,DPSTVOI),'Période'=CPST,'Nombre'=count(NVOI)
>>> from HREH3M
>>> group by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>>> order by CPST,NVOI,datepart(yy,DPSTVOI),datepart(mm,DPSTVOI)
>>>
>>> The problem is with COMPUTE claude, but I can't understand why.
>>>
>>> please help me to solve this.
>>>
>>> thanks in advance
>>>
>>> regards
>>>
>>>     Laurent
>>>
>>>
>>>
>
>
Author
20 Oct 2005 4:55 PM
David Portas
I suggest you don't use COMPUTE / COMPUTE BY unless it's essential to
maintain Sybase compatibility. COMPUTE is legacy stuff that was
deprecated long ago. Take a look at CUBE / ROLLUP in Books Online -
it's a much more powerful feature.

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button