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
 Transact-SQL (2000)
 How to store the result in stored procedure?

Author  Topic 

danyeung
Posting Yak Master

102 Posts

Posted - 2006-08-14 : 18:09:07
Can I get a dataset in stored procedure and use the dataset to join with and other table? For example,

Select top 5 ProductName, sum(TotHours) as Hours
from Table1
where entrydate = ‘08/11/2006’
group by ProductName
order by Hours desc

How do I store the result1 (example below) so that I can use it again in the stored procedure?

ProeuctName Hours
ProductA 150
ProductB 120
ProductC 110

Select * from (result1) where ProductName not in (select ProductName from Table2)


Thanks.
DanYeung

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-08-14 : 19:29:03
From the looks of it you can get it in one statement:


Select top 5
t1.ProductName,
sum(t1.TotHours) as Hours
from Table1 t1
left
join Table2 t2 on
t1.ProductName = t2.ProductName
where t1.entrydate = '08/11/2006' and
t2.ProductName is null
group by t1.ProductName
order by t1.Hours desc


Nathan Skerl
Go to Top of Page

danyeung
Posting Yak Master

102 Posts

Posted - 2006-08-15 : 12:01:50
Thanks.
DanYeung
Go to Top of Page
   

- Advertisement -