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

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.

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

Thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.