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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Joining data from a Tempory table

Author  Topic 

Whamoduck
Starting Member

3 Posts

Posted - 2004-09-30 : 09:52:53
I am new to the tempory table experience.
I can create a tempory table using the code below.

How can I join this with data from other tables. Please give example of joining the below temp table with a table called company that has a field categoryid that ='s cat.categoryid.

You help will be appreciated.

create temporary table breakdown
Select industrial.name industry, industrial.categoryId industryId,
cat.name category, cat.categoryId,
sub.name subcategory, sub.categoryId subCategoryId
from (select * from ref_category where parentId = 0) industrial
inner join ref_category cat on cat.parentId =
industrial.categoryId
left join ref_category sub on sub.parentId = cat.categoryId

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-09-30 : 09:59:54


Create Table #temp (industry varchar(100), industryId int, category varchar(100), categoryId int, subCategory varchar(100), subCategoryId int)

Insert Into #temp
Select industrial.name industry, industrial.categoryId industryId,
cat.name category, cat.categoryId,
sub.name subcategory, sub.categoryId subCategoryId
from (select * from ref_category where parentId = 0) industrial
inner join ref_category cat on cat.parentId =
industrial.categoryId
left join ref_category sub on sub.parentId = cat.categoryId


Select *
From #temp A
Inner Join company B
On A.someCol = B.someCol

Drop Table #temp


Corey
Go to Top of Page
   

- Advertisement -