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.
Author |
Topic |
Alexander Barnes
Starting Member
10 Posts |
Posted - 2007-04-07 : 15:57:56
|
Select screening.screening_cd as code, site_name as site, /*more fields*/screening_adtl.notes as longNotesFrom screeningINNER JOIN screening_adtl On screening.screening_cd = screening_adtl.screening_cdWhere code like '07-0328_RIC%'-----Hi SQL friends:My above SQL script only works when I change the "code" in the last line to "screening.screening_cd". I thought the whole point of the alias was to save myelf from having to use these fully qualified names...!! What am I doing wrong? Note that the tables are related by the pk / fk "screening_cd"TIA |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-07 : 16:38:09
|
Is the column CODE present in both tables? If so (if you are not getting an error from SQL Server) do you suppose the query optimizer can decide which to choose?Peter LarssonHelsingborg, Sweden |
|
|
Alexander Barnes
Starting Member
10 Posts |
Posted - 2007-04-11 : 23:37:01
|
Hi Friends:I found a page in a SQL manual telling me that my field aliases will not work in other parts of the SQL statement except in the Order By Clause (I think), so I guess that's that. I guess this makes sense as the query will first need to put together the dataset from the information in the from clause, at which point the fields must match their names in the tables. Live and learn...Thanks. |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-11 : 23:54:22
|
You cannot use aliases in ORDER BY or GROUP BY..************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-12 : 00:00:49
|
quote: Originally posted by dinakar You cannot use aliases in ORDER BY or GROUP BY..************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
You can use aliases in ORDER BY but not in GROUP BY or WHERE clause KH |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-12 : 11:52:58
|
You are right KH. Sorry for misleading the OP.************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
|
|
|
|
|