Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread CASE - how to use it with SUM function
Thu, Dec 6 2007 8:09 AMPermanent Link

Joze
Hi,

I am trying this SQL:

SELECT   M.ID_laboratorija,   M.ID_narocila,   N.Storno,     
 CASE UPPER(N.Storno)
   WHEN 'J' THEN 0
   WHEN 'N' THEN SUM(M.Meritev_skupaj)
 END AS Sestevek                        
INTO   Memory\Temp FROM   Opravljene_meritve M   INNER JOIN Narocila N ON
M.ID_narocila=N.ID_narocila   LEFT OUTER JOIN Opravljene_meritve_delavci D ON
D.ID_opravljene_meritve = M.ID_opravljene_meritve
WHERE   M.ID_narocila=9 GROUP BY ID_laboratorija                       

but I get an error 11949 Invalid use of nonagregated colum in expresion in
SELECT SQL statement at line 0, column 0

I want to use SUM only if N.Storno value='N', otherwise I want value 0 (zero).
Can someone help me with this, please?

Dbisam 4.22, D7

TIA,

Joze
Thu, Dec 6 2007 8:17 AMPermanent Link

Joze
Hi,

I just find an answer to my question in one of todays answers to someone else...

Smile

Thanks

Best regards,

Joze

Image