SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Use results from one column for another column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pvong
Yak Posting Veteran

52 Posts

Posted - 01/04/2013 :  18:00:50  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 01/04/2013 :  20:40:59  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000