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
 Referencing AS in same select statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sciman
Starting Member

2 Posts

Posted - 07/11/2012 :  18:05:19  Show Profile  Reply with Quote
Hello. I was wondering if it is possible to use the AS statement and then reference it in the same select region of a tsql statement.
Example
SELECT A+B AS C, C+2 as X

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 07/11/2012 :  18:07:01  Show Profile  Visit tkizer's Homepage  Reply with Quote
You can use a derived table:

SELECT C, C+2 as X
FROM (SELECT A+B AS C...) t
...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Edited by - tkizer on 07/11/2012 18:07:17
Go to Top of Page

sciman
Starting Member

2 Posts

Posted - 07/11/2012 :  18:18:58  Show Profile  Reply with Quote
Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 07/11/2012 :  18:29:55  Show Profile  Visit tkizer's Homepage  Reply with Quote
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
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