0

Hi All,

I am pulling out info from my db and need to tjeck if a column is 0, if it is then i need to SUM 3 other columns and pull out that total.

I want to use the CASE keyword and tjeck for this, but am doing something wrong, as I keep getting an error.

This is my code:

$sql = SELECT pris, skin_year, ialt,
CASE ialt
WHEN 0
THEN ialt = SUM('ær,vedrur,lamp')
END
FROM skind_statistik
WHERE kunde_id = x
Gives my a syntax error..

Ialt default value is set to zero, and the datatype is an integer.

Best, Klemmme

2
Contributors
2
Replies
10
Views
3 Years
Discussion Span
Last Post by klemme
1

I think it should be:

SELECT pris, skin_year, 
    CASE ialt
        WHEN 0 THEN SUM(ær,vedrur,lamp)
        ELSE ialt
    END AS ialt
FROM skind_statistik
WHERE kunde_id = x

Can't test right now.

0

Yep that worked, removing the qoutes and then I added + in between the SUM values + AS 'ialt'...

Thanks for your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.