SQLTeam.com | Weblogs | Forums

Trying to Use Case Statement Results

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

WHEN Status = "A" THEN ""
WHEN Status = "Gm3" THEN GM1+GM2
END) AS "Case1 "

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

try this

Select SUM(CASE1) as [running total] from (
Select status
,case status
when 'A' then ''
when 'Gm3' then GM1+GM2
END AS 'CASE1' from #temp) a


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.


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 ...

Thanks for info.