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 alias name as a column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vignesht50
Yak Posting Veteran

77 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

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
165 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])
AS
(
SELECT *,FinanceValue2005 - FinanceValue2004 AS [FinanceValue Variance] FROM @Table
)
SELECT *,[FinanceValue Variance] * 2.50 AS [New Variance] FROM CTE


Veera
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.03 seconds. Powered By: Snitz Forums 2000