rlking12
asked on
division in MS SQL
trying to divide 8518.36 by 22130 and getting null as the value.
It should be 0.384923.....
Need help..
thanks
It should be 0.384923.....
Need help..
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are a couple of conditions that can resolve to NULL:
1) If orderdtl.ordernum is null and project.number02 <> 0 and project.number02 is null
(Case when orderdtl.ordernum is null Then (case project.number02 when 0 then 1 else project.number02 end)
2) If orderdtl.ordernum is not null and (((isnull(orderdtl.docunit price,0) * isnull(orderdtl.orderqty,0 )) - isnull(tblmisc.MiscAmt,0)) - isnull(orderdtl.discount,0 )) <> 0
(case((isnull(orderdtl.doc unitprice, 0) * isnull(orderdtl.orderqty,0 )) - isnull(tblmisc.MiscAmt,0)) - isnull(orderdtl.discount,0 ) when 0 then 1 end) -- The CASE has no ELSE
1) If orderdtl.ordernum is null and project.number02 <> 0 and project.number02 is null
(Case when orderdtl.ordernum is null Then (case project.number02 when 0 then 1 else project.number02 end)
2) If orderdtl.ordernum is not null and (((isnull(orderdtl.docunit
(case((isnull(orderdtl.doc
Long time no see, Brandon :)
ASKER
((Case when orderdtl.ordernum is null Then (case project.number02 when 0 then 1 else project.number02 end)
ELSE ((isnull(orderdtl.docunitp rice,0) * isnull(orderdtl.orderqty,0 )) - isnull(tblmisc.MiscAmt,0)) - isnull(orderdtl.discount,0 )
END)) - isnull(EstMaterial.Act_Cos t,0))
the top part evalutes to: 8518.36
/ (Case when orderdtl.ordernum is null Then (case project.number02 when 0 then 1 else project.number02 end)
ELSE (case((isnull(orderdtl.doc unitprice, 0) * isnull(orderdtl.orderqty,0 )) - isnull(tblmisc.MiscAmt,0)) - isnull(orderdtl.discount,0 ) when 0 then 1 end)
END)) as Actual_GPPerc
The bottom evalutes to: 22130
I've placed them in seperate fields and it gives me a vaue separately. So if you manula divide them on a caluculator you get: 0.384923
ELSE ((isnull(orderdtl.docunitp
END)) - isnull(EstMaterial.Act_Cos
the top part evalutes to: 8518.36
/ (Case when orderdtl.ordernum is null Then (case project.number02 when 0 then 1 else project.number02 end)
ELSE (case((isnull(orderdtl.doc
END)) as Actual_GPPerc
The bottom evalutes to: 22130
I've placed them in seperate fields and it gives me a vaue separately. So if you manula divide them on a caluculator you get: 0.384923
ASKER
IF the values show up independant of the division... shouldn't the division work?
ASKER
Select 8518.36 / cast(22130 as float) still get null value
What version and service pack level of SQL Server?
ASKER
SQL Server 2005
Microsoft SQL Server Management Studio 9.00.3042.00
Microsoft SQL Server Management Studio 9.00.3042.00
It does not make sense to me. Select 8518.36 / cast(22130 as float) is not supposed to return NULL at all.
ASKER
thanks....
ASKER
ELSE ((isnull(orderdtl.docunitp
END)) - isnull(EstMaterial.Act_Cos
ELSE (case((isnull(orderdtl.doc
END)) as Actual_GPPerc,