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 December 16th, 2003, 07:31 PM
Authorized User
Join Date: Nov 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Two selects in one procedure


Basically I have a stored procedure that inserts values into a temp table, what I want to do is add a second select to the procedure that takes one of the returned values so I can query another table.

How can I take a returned value then add it to a variable so that I can run the second query.

Thanks in advance for any help
Old December 17th, 2003, 12:03 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc

you can try creating a view
SELECT col1,col2, col3
FROM yourtable
WHERE col1 = 'value'

Then query the results of the view

Subquery: Simple Example

Let's say we need to provide a list of all of our customers that have placed orders for more than $1000. We don't need the order information, just the customer information. We could accomplish this with a subquery as follows:
  FROM customer
                    FROM orders
                   WHERE ItemsTotal > 1000)
The subquery is the portion enclosed in parentheses. The above expression tells Local SQL to execute the subquery first, which forms a list of customer numbers for all orders greater than $1000. The other query uses this result as the criteria list for the IN function. In this case, the same result could've been accomplished with an INNER JOIN and a SELECT DISTINCT. We were illustrating a simple example - not all subqueries are so trivial.
Old December 17th, 2003, 05:28 AM
Authorized User
Join Date: Jun 2003
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts

Hope this helps

DECLARE @var varchar(20)

SELECT @var = column
FROM yourtemptable
WHERE whatever = whatever

FROM secondtable
WHERE whatever = @var

Similar Threads
Thread Thread Starter Forum Replies Last Post
listbox always selects index 0 Colonel Angus ASP.NET 2.0 Professional 5 August 18th, 2008 01:11 PM
Put together 2 selects results in a single one romulo.petri SQL Language 3 March 6th, 2008 03:43 AM
trying to get data from multiple selects ceevk1 VB Databases Basics 1 April 3rd, 2007 12:05 PM
How to combine two value-of selects? myhtpc XSLT 2 February 14th, 2006 06:20 AM
Multiple Selects in SQL QueryStrings doonman BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 6 January 30th, 2006 07:01 AM

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