SELECT
    (CASE 
        WHEN field1 > 0                         -- when field1 > 0
            THEN field1 
        WHEN field2 IS NULL OR field3 IS NULL   -- when field1 = 0 or NULL
            THEN 0
        ELSE field2 * field3 
    END) AS result
FROM table ;

DB[:table].select(Sequel.case({Sequel[:field1] > 0 => :field1, (Sequel[:field2] 
=~ nil)|(Sequel[:field3] =~ nil)=>0},Sequel[:field2]*:field3).as(:result)

Apologies for typos, posting from phone.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to