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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 reusing column names

Author  Topic 

npaiva
Starting Member

1 Post

Posted - 2005-07-19 : 12:10:22
Dear All,

I'm a SQL SERVER newbie which is trying to build an sql command that can reuse eacg previous column, on the statement, to perform some kind of calculation. In a simplified example it'll would be something like this:

select len(a) as Col1, [Col1]*3 as Col2 from Table

In MS Access this goes smooth, but in T-SQL it's not possible?! Is there any possible workaround?

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-07-19 : 12:17:06
nearest you can get is...
select col1, col1*3 as col2 from (select len(a) as Col1 from table1) a
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-07-19 : 12:18:43
Sorry to say, it won't let you do that. You can either do this:

SELECT LEN(a) AS Col1, LEN(a)*3 AS Col2 FROM Table

Or this:

SELECT Subqry.Col1, Subqry.Col1*3 AS Col2
FROM
(SELECT LEN(a) AS Col1 FROM Table) AS Subqry

Go to Top of Page
   

- Advertisement -