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 2008 Forums
 Transact-SQL (2008)
 Column alias

Author  Topic 

Mahavirjadhav
Starting Member

18 Posts

Posted - 2014-11-27 : 19:49:13
Hi,
I have written following query

select biz_id as Id1 from biz_info where Id1> 5000

The above query is giving error 'Invalid column name Id1'

Please help.

Thanks.

Mahavir

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-11-28 : 01:51:31
You can't use this alias unless it is a subquery

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-11-28 : 05:28:33
The order of evaluation of the main SQL clauses is:

FROM, including JOINS
WHERE
GROUP BY
HAVING
SELECT
ORDER BY

As you can see, the alias Id1 has not yet been defined when the WHERE clause is evaluated.
Go to Top of Page

marcusn25
Yak Posting Veteran

56 Posts

Posted - 2014-11-29 : 19:46:56
select
*
from
(
select
biz_id as Id1
from biz_info
) biz
where biz.Id1> 5000

Marcus

I learn something new everyday.
Go to Top of Page
   

- Advertisement -