Dinup Kandel
Dinup Kandel

Reputation: 2505

need help for sql query on case

i had table as

s.no--------------Amount--------accCode-----discount-----status
  1-----------------20-------------2.1-------10.00------------yes
  2-----------------30-------------2.1-------6.00-------------yes
  3-----------------20-------------3.1-------10.00------------No
  4-----------------30-------------2.1-------10.00------------yes
  5-----------------40-------------3.1-------5.00-------------No
  6-----------------20-------------2.1-------10.00------------yes

i need to select all the row from the table with its values but i need to show the discount amount 0.00 if its status is No Otherwise i need the same as in table. please could anybody help me on this. thanks for all.

Upvotes: 0

Views: 33

Answers (2)

marc_s
marc_s

Reputation: 754348

Somethnig like this?

SELECT
   sno, amount, acccode,
   CASE [status]
     WHEN 'No' THEN 0.0
     ELSE discount
   END AS 'discount' 
FROM dbo.YourTable

Upvotes: 1

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

case [status]
  when 'No' then 0
  else discount
end as discount  

Upvotes: 0

Related Questions