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)
 syntax question

Author  Topic 

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-10-02 : 16:26:32
if I have something like this

select x.a,x.b,(x.c+x.d+x.e) as result, result-x.a
from table

that won't work, because result is an invalid column name in this case.
How can I write this so I don't have to do this:

select x.a,x.b,(x.c+x.d+x.e) as result, (x.c+x.d+x.e)-x.a
from table


thanx

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-02 : 16:31:57
select result, result - a
from (select x.a,x.b,(x.c+x.d+x.e) as result, x.a from table) t

Tara Kizer
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-10-02 : 16:42:24
many thanx
Go to Top of Page
   

- Advertisement -