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)
 Refering an Alias

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2005-12-02 : 11:03:40
Hello - I don't understand why I'm getting this error message. Thanks.

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'DirName'.


SELECT TCompanies.Ticker, TCompanies.Industry,
(TDirectors.DirFName + ' ' + TDirectors.DirLName) As DirName,
TDirectors.IDDir, TDirectorships.DirStatus
FROM TCompanies INNER JOIN TDirectorships ON TCompanies.Ticker = TDirectorships.Ticker
INNER JOIN TDirectors ON TDirectorships.IDDir = TDirectors.IDDir
WHERE (TDirectors.DirFName LIKE 'richard brown%')
OR (TDirectors.DirLName LIKE 'richard brown%')
OR (DirName LIKE '%richard brown%')

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-12-02 : 11:10:30
you can't reference an alias column in a where.
you can do:
select * from
(
SELECT TCompanies.Ticker, TCompanies.Industry,
(TDirectors.DirFName + ' ' + TDirectors.DirLName) As DirName,
TDirectors.IDDir, TDirectorships.DirStatus
FROM TCompanies INNER JOIN TDirectorships ON TCompanies.Ticker = TDirectorships.Ticker
INNER JOIN TDirectors ON TDirectorships.IDDir = TDirectors.IDDir
WHERE (TDirectors.DirFName LIKE 'richard brown%')
OR (TDirectors.DirLName LIKE 'richard brown%')
) t
where (DirName LIKE '%richard brown%')

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-03 : 02:09:19
or use the same columns in place of DirName

SELECT TCompanies.Ticker, TCompanies.Industry,
(TDirectors.DirFName + ' ' + TDirectors.DirLName) As DirName,
TDirectors.IDDir, TDirectorships.DirStatus
FROM TCompanies INNER JOIN TDirectorships ON TCompanies.Ticker = TDirectorships.Ticker
INNER JOIN TDirectors ON TDirectorships.IDDir = TDirectors.IDDir
WHERE (TDirectors.DirFName LIKE 'richard brown%')
OR (TDirectors.DirLName LIKE 'richard brown%')
OR (TDirectors.DirFName + ' ' + TDirectors.DirLName LIKE '%richard brown%')


Madhivanan

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

- Advertisement -