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 |
|
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2011-11-09 : 05:39:38
|
| Hi I want to Join multiple temp tables which don't have any relation each other. Due to that i can't able to write 'ON' condition.I have tried to add a a unique column to all temp tables to join them based on that Unique column, however if any one of these temp tables have no rows then my unique is not inserted into temp tableand the final join result also returns no rows |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-09 : 06:16:00
|
| Try a left joinselect *from #tmp1 t1left join #tmp2 on t2.id = t1.idleft join #tmp3 on t3.id = t1.idIf there's no biggest tableselect *from (select id frmo #tmp1 union select id from #tmp2 union select id from #tmp3) tleft join #tmp1 on t1.id = t.idleft join #tmp2 on t2.id = t.idleft join #tmp3 on t3.id = t.idBut you probably should think about why you want to do this.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 06:26:26
|
quote: Originally posted by Sql_forum Hi I want to Join multiple temp tables which don't have any relation each other. Due to that i can't able to write 'ON' condition.I have tried to add a a unique column to all temp tables to join them based on that Unique column, however if any one of these temp tables have no rows then my unique is not inserted into temp tableand the final join result also returns no rows
if they have no relationship with each other what will be use in adding unique id and relating them with that?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-11-09 : 06:29:29
|
show us your table, sample data and the exprected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|