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
 Referencing AS in same select statement

Author  Topic 

sciman
Starting Member

2 Posts

Posted - 2012-07-11 : 18:05:19
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

38200 Posts

Posted - 2012-07-11 : 18:07:01
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
Go to Top of Page

sciman
Starting Member

2 Posts

Posted - 2012-07-11 : 18:18:58
Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-11 : 18:29:55
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
   

- Advertisement -