Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Conversion
Message
De
29/09/2011 14:27:34
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01525186
Message ID:
01525192
Vues:
40
Yeah. I assume you mean remove from the Group By list. But this code:
select crsB.[category], jul, [fisyear]
from (select distinct [category] from [RTA-Revenues]) as crsA 
inner join (
select [fisYear], [category],
CASE WHEN month([receiveddate])=7 THEN sum([AMOUNT]) ELSE CAST(0 AS numeric(12,2)) END as Jul
from [rta-revenues]
group by [FISYEAR], [CATEGORY]) as crsB
on crsA.[CATEGORY] = crsB.[CATEGORY]
order by [FISYEAR], [CATEGORY]
produces this error.

Msg 8120, Level 16, State 1, Line 33
Column 'rta-revenues.RECEIVEDDATE' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.


So what to do?



>Remove columns you don't want to group on.
>
>>Thanks Sergy. You are amazing! That gets me to here.
>>
>>select crsB.category, jul, [fisyear]
>>from (select distinct category from [RTA-Revenues]) as crsA 
>>inner join (
>>select [fisYear], [category],
>>CASE WHEN month([receiveddate])=7 THEN sum(AMOUNT) ELSE CAST(0 AS numeric(12,2)) END as Jul
>>from [rta-revenues]
>>group by receiveddate, FISYEAR, CATEGORY) as crsB
>>on crsA.CATEGORY = crsB.CATEGORY
>>order by FISYEAR
>>
>>
>>Note that sqlserver is insisting on having receiveddate in the group by clause. Something I did not have before. As above it runs but produces multiple rows for each fisyear/category combination. Something I do not want.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform