Simple CR SQL Command

giovedì 01 febbraio 2007 - 10.04

aleplgr Profilo | Junior Member

Hi! I have this simple sql command that works fine:

SELECT MIN(ESCALESCAP.CLAU), ESCALESCAP.C_HISTORIA
FROM
ESCALESCAP ESCALESCAP
WHERE ( ESCALESCAP.CLAU>2615 And
ESCALESCAP.CLAU <2635)
GROUP BY ESCALESCAP.C_HISTORIA

But when I add another field to the SELECT clause from the same ESCALESCAP table it prints me an error... and can't find why

freeteo Profilo | Guru

hi,
this is a "query sintax" problem
The problem is that u ar grouping fields and is necessary to specify the operation to "aggregate" the fields that aren't in the group operation.
For the first field u specify "min" as the operation to make, in the other is not necessary because the operation is exactly "group".
So, in ur case:

SELECT MIN(ESCALESCAP.CLAU), ESCALESCAP.C_HISTORIA , MIN(otherfield),MAX(otherfield2)....
FROM
ESCALESCAP ESCALESCAP
WHERE ( ESCALESCAP.CLAU>2615 And
ESCALESCAP.CLAU <2635)
GROUP BY ESCALESCAP.C_HISTORIA

hope it help


ciao.

Matteo Raumer
[MCAD .net]
http://blogs.dotnethell.it/freeteo
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5