SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL statement - newbie
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Alexander Barnes
Starting Member

USA
10 Posts

Posted - 04/07/2007 :  15:57:56  Show Profile  Reply with Quote
Select screening.screening_cd as code, site_name as site,
/*more fields*/
screening_adtl.notes as longNotes

From screening
INNER JOIN screening_adtl On screening.screening_cd = screening_adtl.screening_cd

Where 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

Sweden
29910 Posts

Posted - 04/07/2007 :  16:38:09  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 Larsson
Helsingborg, Sweden
Go to Top of Page

Alexander Barnes
Starting Member

USA
10 Posts

Posted - 04/11/2007 :  23:37:01  Show Profile  Reply with Quote
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.




Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 04/11/2007 :  23:54:22  Show Profile  Visit dinakar's Homepage  Reply with Quote
You cannot use aliases in ORDER BY or GROUP BY..


************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17437 Posts

Posted - 04/12/2007 :  00:00:49  Show Profile  Reply with Quote
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

Go to Top of Page

dinakar
Flowing Fount of Yak Knowledge

USA
2507 Posts

Posted - 04/12/2007 :  11:52:58  Show Profile  Visit dinakar's Homepage  Reply with Quote
You are right KH. Sorry for misleading the OP.


************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000