Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using CASE within SUM()
Message
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01035999
Message ID:
01036003
Vues:
12
This message has been marked as the solution to the initial question of the thread.
Del,

You're missing comma after previous column and I would use BETWEEN operator for readability. I made corrections below in the code.

>I am converting a VFP SELECT-SQL statement to operate on a SQL Server table. Below is an attempt and there's something wrong with the last SUM(), I think ...
>
>
>SELECT cITEM,
>	SUM(nGOODLBS) AS qcItemGood,
>	SUM(nSCRAPLBS) AS qnItemScrap,
>	SUM(CASE cPCODE
>		WHEN '100' THEN nTIMEINT
>		ELSE 00.00
		END) AS qnItemRun,   -- <-- Missng comma
	SUM(CASE WHEN cPCODE BETWEEN '101' AND '199' THEN nTIMEINT
>		ELSE 00.00
>		END) AS qnItemDown
>FROM EXTRMAST
>	JOIN EXTRDETL
>		ON EXTRMAST.EXTRMASTID = EXTRDETL.EXTRMASTID
>WHERE dSHIFTDATE BETWEEN '07/01/2004' AND '06/30/2005'
>GROUP BY cITEM
>ORDER BY 2 DESC
>
>
>In VFP, the last field expression was the following, so this may demonstrate further what I'm trying to accomplish.
>
>
>SUM(IIF(BETWEEN(cPCODE, '100', '199'), nTIMEINT, 00.00)) AS qnItemDown
>
>
>I'm looking at the BOL topic 'Conditional Data Processing Using Case' and it appears I have the case constructed as the second example, but perhaps doing this within a SUM is not allowed. How do I accomplish the VFP equivalent in SQL Server?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform