SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Join based on derived table with a temp table

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Join based on derived table with a temp table
Author Message
judahr



Joined: 09 Mar 2007
Posts: 319
Country: United States

Post Join based on derived table with a temp table Reply with quote
v 5.0.74
Code:

CREATE TABLE #ID (ID INT)

SELECT ia2.
FROM dbo.Table1 t
   LEFT OUTER JOIN (SELECT ia.Table2ID, ia.Table1ID
                       FROM #ID i  inner join dbo.Table2 ia ON i.ID = ia.Table2ID) ia2
      ON ia2.Table1ID = t.Table1ID


In the Select clause, ia2. doesn't produce the column list for the ia2 derived table. If you remove the temp table, it works fine. Temp table on its own works fine. I don't know if this is new to 5 or has always been there.

5 is pretty solid so far. I haven't used the new features.
Thu Mar 18, 2010 11:57 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Unfortunately it cannot guess column names from a derived table based on the temp table which doesn't physically exist, it relies internally on certain SQL Server engine functions which in this case are unable needs to find temp table column names and definitions in the system catalog. This is not the same as parsing column names for the internal sub-query.

I guess, if you create the temp table, the suggestions for derived table columns will begin working as expected. Hope this makes sense.
Thu Mar 18, 2010 6:51 pm View user's profile Send private message
judahr



Joined: 09 Mar 2007
Posts: 319
Country: United States

Post Reply with quote
That makes sense. However, it is able to figure out the columns if it was directly joined as below:

Code:
CREATE TABLE #ID (ID INT)

SELECT i.
FROM dbo.Table1 t
   LEFT OUTER JOIN #ID i 
      ON ia2.Table1ID = i.Table1ID

Fri Mar 19, 2010 7:49 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
That's correct. That's what I meant by "This is not the same as parsing column names for an internal sub-query" sorry for not being clear.

In case of derived tables, the entire subquery is evaluated as if it was a view. So that if any component of a view is missing, it cannot be evaluated.
Fri Mar 19, 2010 8:38 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.