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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sql calculation

Author  Topic 

magicman
Starting Member

6 Posts

Posted - 2008-01-16 : 03:39:59
Hi,
I have created a view called vwColour from a table called tblColurs, the fieds I am interested in are Red, Blue, Orange. However the value in table tbBlue is sometimes NUll. The Calculation I am trying to perform on each row of the view is tbRed + tbBlue * tbOrange.

My syntax is just adding not multiplying correctly, can you help?

dbo.tblColours.Red +ISNULL(dbo.tblColours.Blue,0) * dbo.tblColours.Orange AS NewTotal.

The orange value is not being calculated?

red blue orange NewTotal
2 4 6 6 not 12?

Thanks if anyboby can help!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-16 : 03:44:10
quote:
Originally posted by magicman

Hi,
I have created a view called vwColour from a table called tblColurs, the fieds I am interested in are Red, Blue, Orange. However the value in table tbBlue is sometimes NUll. The Calculation I am trying to perform on each row of the view is tbRed + tbBlue * tbOrange.

My syntax is just adding not multiplying correctly, can you help?

dbo.tblColours.Red +ISNULL(dbo.tblColours.Blue,0) * dbo.tblColours.Orange AS NewTotal.

The orange value is not being calculated?

red blue orange NewTotal
2 4 6 6 not 12?

Thanks if anyboby can help!


how will 2+4*6 be equal to 12?are you trying to perform 2+4+6?
Go to Top of Page

magicman
Starting Member

6 Posts

Posted - 2008-01-16 : 03:48:08
No sorry, what I meant was i.e

I am trying to perform 2 + 4 * 6

I am getting the result as 2+4, i.e 6 not 36 which is what I want,
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 03:50:13
You need to post proper sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 03:52:05
Try

(dbo.tblColours.Red +ISNULL(dbo.tblColours.Blue,0)) * dbo.tblColours.Orange AS NewTotal.


see the difference

select 2 + 4 * 6,(2 + 4) * 6



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

magicman
Starting Member

6 Posts

Posted - 2008-01-17 : 01:50:45
Voila, thx
Go to Top of Page
   

- Advertisement -