SQLTeam.com | Weblogs | Forums

Trying to Use Case Statement Results

sql2008
sql2012

#1

I have used a case statement to anaalyze data and show them in a table column.

(CASE
WHEN Status = "A" THEN ""
WHEN Status = "Gm3" THEN GM1+GM2
ELSE GM1+GM2+GM3
END) AS "Case1 "

How can I sum the values from this case to a "running total"?


#2

try this

Select SUM(CASE1) as [running total] from (
Select status
,Gm1
,Gm2
,Gm3
,GmCnt
,TOTAL
,RSum
,case status
when 'A' then ''
when 'Gm3' then GM1+GM2
ELSE GM1+GM2+GM3
END AS 'CASE1' from #temp) a


#3

Hello

Thanks for your input!

Have tried this with few variations but could not get past this error?

Included a jpg of MySQL code and error msg for clarity.

Have not used many case statements or square brackets very often but like the possibilities.

Ray


#4

This is a Microsoft SQL Server forum, so you might not find people here familiar with MySQL ...

Pretty sure they don't work in MySQL ...


#5

Thanks for info.