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
 Using alias Column names for calculations

Author  Topic 

chiman

21 Posts

Posted - 2007-10-03 : 17:18:49
Hi,
I want to have a query where in i can use alias column names in the same query.
like eg
select 1 as 'a', 2 as 'b', a+b as 'c'

note that this query is getting big and is using sub queries.


Kindly help.

Thanks

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-10-03 : 17:44:08
Do you have a question?



CODO ERGO SUM
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2007-10-03 : 17:46:25
quote:
Originally posted by renu.khot@gmail.com

Hi,
I want to have a query where in i can use alias column names in the same query.
like eg
select 1 as 'a', 2 as 'b', a+b as 'c'

note that this query is getting big and is using sub queries.


Kindly help.

Thanks



Yes
Go to Top of Page

chiman

21 Posts

Posted - 2007-10-03 : 17:46:50
my question is,
how would u use alias columns names in the calculation!

quote:
Originally posted by Michael Valentine Jones

Do you have a question?



CODO ERGO SUM

Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-03 : 17:53:52
I don't think you can in one select. It doesn't know what a and b are yet. You could do something like this:

select a as a, b as b, a+b as c from
(select 1 as a, 2 as b) t
Go to Top of Page

chiman

21 Posts

Posted - 2007-10-03 : 17:57:00
thanks, i got it anyways....
a and b are just eg values!

quote:
Originally posted by Van

I don't think you can in one select. It doesn't know what a and b are yet. You could do something like this:

select a as a, b as b, a+b as c from
(select 1 as a, 2 as b) t

Go to Top of Page
   

- Advertisement -