Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

sql case when as statement

Posted on 2009-12-18
4
Medium Priority
?
316 Views
Last Modified: 2012-05-08
can someone help me with this sql statment. it will not work, it keep saying invalid new then.  

select
case when ((slsrepplan.planamt = 0 then 0) else slsrepplan.actamt/slsrepplan.planamt) as "plan%"

from slsrepplan
0
Comment
Question by:kelsanit
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 26083753

select
case when slsrepplan.planamt = 0 then 0 else slsrepplan.actamt/slsrepplan.planamt END as "plan%"

from slsrepplan
0
 
LVL 10

Expert Comment

by:lof
ID: 26083759
Try this
select
case when slsrepplan.planamt = 0 then 0 else slsrepplan.actamt/slsrepplan.planamt end as "plan%"
from slsrepplan

Open in new window

0
 
LVL 26

Expert Comment

by:tigin44
ID: 26084343
select      case when slsrepplan.planamt = 0 then 0
                   else slsrepplan.actamt/slsrepplan.planamt)
            end as "plan%"
from slsrepplan
0
 
LVL 14

Expert Comment

by:shru_0409
ID: 26086292
if slsrepplan.planamt column default zero the this above case statement is prefectly rigth. if not than u have to write link this

select case when nvl(slsrepplan.planamt,0) = 0 then 0 else slsrepplan.actamt/slsrepplan.planamt End as "plan%"
decode

u can write also like this

select decode (slsrepplan.planamt,0,0,slsrepplan.actamt/slsrepplan.planamt) as "plan%" from slsrepplan
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question