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
 Use results from one column for another column

Author  Topic 

pvong
Yak Posting Veteran

58 Posts

Posted - 2013-01-04 : 18:00:50
Doing this in SQL 2008.

Is it possible to use the results of one column to calculate another column? Example:

Select .. VERY LONG FORMULA as Results1

I need another column with a CASE so..

CASE Result1 < 100 Then something as Results2

Is it possible to do something like this or do I have to do the whole long formula again like...

CASE VERY LONG FORMULA < 100 Then something as Result2

I already have Results1 and it's silly to do it again just to calculate Results2.

God I hope this isn't too confusing.

Thanks in advance.
Phil

------------------------------
Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2
Be kind to the newbies because you were once there.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-04 : 20:40:59
you can do in both ways

either

CASE VERY LONG FORMULA < 100 Then something as Result2


or make first result into derved table and then use it like

SELECT ....,
CASE Result1 < 100 Then something as Results2,
..
FROM
(
SELECT ...,
VERY LONG FORMULA as Results1
FROM
....
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -