Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Divide two columns with null values

Author  Topic 

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-08-14 : 03:30:05
Hi,

I am trying to divide these two columns and need
suggestions.

parsename('$'+ Convert(varchar,Convert(money,Q.[Product Cost]-R.[Shared Cost]),1),2) as [Pre Cost],
parsename('$'+ Convert(varchar,Convert(money,R.[New Product Cost]-R.[Shared Cost]),1),2) as [Post Cost]

Formula:
[Post Cost] / [Pre Cost]

Expected:

If [Post Cost] is null then I would need to assign 1 and divide by [Pre Cost] and similarly if [Pre Cost] is null then I would need to assign 1 so that I can divide [Post Cost] / [Pre Cost]

Really appreciate any help on this.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-14 : 07:57:50
[code]
isnull([Post Cost],1) / Isnull([Pre Cost],1)
[/code]
Go to Top of Page
   

- Advertisement -