| Author |
Topic |
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2008-10-13 : 10:57:24
|
| Hi everyone -I cannot believe i am having this much trouble with these joins...I have a master table that references several sub tables,and I need to join the sub-tables based on the ID in the master table...SELECT u.username as [User_Name], f.fullname as [NFL_Favorite], h.fullname as [NHL_Favorite]FROM ##UserSelection as U inner join [prod_central].[football].[dbo].[team] as f inner join [prod_central].[hockey].[dbo].[team] as hon u.nfl_favorite = f.teamid and u.nhl_favorite = h.teamidWHERE [username] IS NOT NULL AND len([username])>1How can i screw this up???i get an syntax error on WHERE....UGH, can someone show me the light?thankstony |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-13 : 10:59:36
|
[code]SELECT u.username as [User_Name], f.fullname as [NFL_Favorite], h.fullname as [NHL_Favorite]FROM ##UserSelection as Uinner join [prod_central].[football].[dbo].[team] as f on u.nfl_favorite = f.teamid inner join [prod_central].[hockey].[dbo].[team] as h on u.nhl_favorite = h.teamidWHERE len([username]) > 1[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2008-10-13 : 11:04:14
|
| Excellent -Here is what I finished withSELECT u.username as [User_Name], f.fullname as [NFL_Favorite], h.fullname as [NHL_Favorite]FROM ##UserSelection as U, [prod_central].[football].[dbo].[team] as f, [prod_central].[hockey].[dbo].[team] as hWHERE u.nfl_favorite = f.teamid andu.nhl_favorite = h.teamidand[username] IS NOT NULL AND len([username])>1Thanks for the reply!!take caretony |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-13 : 11:08:45
|
Why1) Use CROSS JOIN and then filter?2) Both have IS NOT NULL and LEN() > 1? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-13 : 11:12:15
|
| Please note that better to use ANSI type join syntax as Peso suggested as this will not supported in future versions of sql server. |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2008-10-13 : 16:03:25
|
| Hi everyone -The question, 2) Both have IS NOT NULL and LEN() > 1?is because the DAL would allow a SPACE to be used as a valid username... since creation it has been corrected, but users have created records with the space as the user name.thanks for the replytake caretony |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-14 : 00:17:56
|
Try thisSELECT LEN(' ')There is one space between the single quotes.The result is 0, since LEN doesn't count trailing spaces.So you only needAND userName > '' to filter out your records. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2008-10-14 : 03:27:57
|
| If username is null then i think we can also use thisisnull(username,'')<>'' instead of [username] IS NOT NULL AND len([username])>1 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-14 : 03:55:01
|
[code]AND userName > ''[/code]will be enough. Why filter same thing twice? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-14 : 09:46:45
|
| or AND userName <> ''MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-14 : 09:55:21
|
Show me something that is less than empty space '' E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|