Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2003, 06:32 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a SP result set in a FROM clause

Hi all:

For example, I have an SP (stored proc) named sp_getinvoices that returns a result set. How can i use this SP in a select statement?

Like...
select * from execute("sp_getinvoices") where invdate > '01/01/2003'

invdate is a field in the result set of the sp that we can get by simply issuing execute sp_getinvoices.

I know that statement won't work, but this could give us an idea what I want to achieve.

TIA...
Bernard
 
Old October 3rd, 2003, 05:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can do this by:
1. creating a temporary table which matches the structure of the "table" that the sp returns, then
2. use an INSERT EXEC statement to put the data into the temporary table, then
3. do a SELECT against the temporary table including your WHERE clause

Here's an example using one of the stored procs in Northwind:
Code:
CREATE TABLE #tmp1
(  ProductName nvarchar(40),
   UnitPrice money)

INSERT #tmp1
EXEC [Ten Most Expensive Products]

SELECT * FROM #tmp1 WHERE UnitPrice < 100

DROP TABLE #tmp1
hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting a result set to a vector cakalanka Java Databases 1 March 24th, 2008 07:33 AM
result of SP to be insert into table drachx SQL Server 2000 1 October 3rd, 2005 12:38 AM
write result set bmains SQL Server 2000 11 March 9th, 2004 09:31 AM
Result set jemacc SQL Server 2000 0 December 19th, 2003 07:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.