Muhammad Bilal
Muhammad Bilal

Reputation: 25

Sybase SQL : Use of Condition operator in IF and CASE statement

I want to use Greater than and less than operator within IF and CASE statement but its not working. I unable to found out any solution. What I want to do is if TotalPurchases are greater than 10 than replace all values with 0 otherwise replace all values with q

Select  pur_mst.n_srno, act_mst.c_code, act_mst.c_name , 
sum (pur_mst.n_subtotal)TotalPurchases,
            ( CASE TotalPurchases 
            WHEN TotalPurchases > 10
            THEN TotalPurchases = 0
            ELSE TotalPurchases  = 20 ) as type
            from act_mst join pur_mst ON
            act_mst.c_code = pur_mst.c_supp_code  
            Group by pur_mst.n_srno,
            act_mst.c_code, act_mst.c_name

Upvotes: 0

Views: 6413

Answers (1)

Kapil
Kapil

Reputation: 987

Correcting the syntax for Case when

 Select  pur_mst.n_srno, act_mst.c_code, act_mst.c_name , 
        CASE 
        WHEN sum (pur_mst.n_subtotal) > 10 THEN  0
        ELSE  20 End as TotalPurchases
        from act_mst join pur_mst ON
        act_mst.c_code = pur_mst.c_supp_code  
        Group by pur_mst.n_srno,
        act_mst.c_code, act_mst.c_name

Upvotes: 1

Related Questions