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)
 Arithmetic

Author  Topic 

JustStrolling
Starting Member

15 Posts

Posted - 2007-10-16 : 07:38:37

I want to take the column values (same table, same row) only if the 'Bit' column for that column is true... and then mulitply it by the column 'Multiplier'.
For instance:

A1 ABit B1 BBit Multiplier
5 True 10 False 1.0
10 True 15 True 1.0



The result I am looking for in each row would be:
5
15

I tried segmenting it up using Aliases and the IIF statement which worked fine. But then I found I can not use Aliases in my arithmetic, so how do I do this?


*Thanks*

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-16 : 07:40:15
IIF? are you using MS Access?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-16 : 07:54:52
SELECT CASE WHEN BBit = True THEN B1 WHEN ABit = True THEN A1 END * Multiplier
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

JustStrolling
Starting Member

15 Posts

Posted - 2007-10-17 : 04:34:06
Hello harsh_athalye,
No, although I actually tried it in Access first and then went to .Net.
The Aliases were stopping me and I just didn't know quite how to do this without them. Initially I was looking at IIF and Coalesce.


Excellent Peso...

Got it to work with my INNER JOINS also

*Thanks*
Go to Top of Page
   

- Advertisement -