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
 Invalid Column Name

Author  Topic 

ikari
Starting Member

2 Posts

Posted - 2007-12-04 : 07:08:23
Hi I'm new to this forum and I seem to be having a basic problem. I have moved from using MS Access to SQL Server and I seem to be having problem with the SQL below.

SELECT Table_A.*, (Statement_A) AS Value_A ,
(Value_A + 4) AS Value_B

FROM Table_A

I keep on getting an error stating invalid column name, I know that statement A is fine because when I move the calculation into Value_B it works.

Can anyone tell me what I am doing wrong?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-04 : 07:11:10
SELECT Table_A.*, (Statement_A) AS Value_A ,
(Statement_A + 4) AS Value_B

FROM Table_A



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-04 : 07:11:34
Since Value_A is a virtual column, you can't refer it in the same SELECT query by its name. Either make it part of derived table or you will have to repeat Statement_A again for calculating Value_B.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

ikari
Starting Member

2 Posts

Posted - 2007-12-04 : 07:49:40
Thank you for the information.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-04 : 07:51:47
Also note that you can directly use alias name only in Order by caluse

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -