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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Use alias name as a column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

82 Posts

Posted - 02/25/2014 :  06:39:09  Show Profile  Reply with Quote
I'm using this query to to calculate yearly finance values.

select [Year],[FinanceValue-2014],[FinanceValue-2013],[FinanceValue-2012],[FinanceValue- 2014]-[FinanceValue-2013] as [FinanceValue Variance]

Now I need to multiply the [FinanceValue Variance] * 2.50 and for that how can I use the alias name as column in the query. I tried this but it says invalid column name.

select [Year],[FinanceValue-2014],[FinanceValue-2013],[FinanceValue-2012],[FinanceValue- 2014]-[FinanceValue-2013] as [FinanceValue Variance], [FinanceValue Variance] * 2.50 as [NewVariance] from Finance

SumofVariance output will be like 5690.5893656 Also how can I show the SumofVariance to round off 4 decimal places like this 5690.5894. Really appreciate any help on this.

Edited by - vignesht50 on 02/25/2014 07:16:30

Posting Yak Master

169 Posts

Posted - 02/25/2014 :  07:35:08  Show Profile  Reply with Quote
DECLARE @Table TABLE (Year INT,FinanceValue2005 INT,FinanceValue2004 INT,FinanceValue2003 INT)
INSERT INTO @Table VALUES(2011,100,90,80)

;With CTE([Year],FinanceValue2005,FinanceValue2004,FinanceValue2003,[FinanceValue Variance])
SELECT *,FinanceValue2005 - FinanceValue2004 AS [FinanceValue Variance] FROM @Table
SELECT *,[FinanceValue Variance] * 2.50 AS [New Variance] FROM CTE

Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000