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
 General SQL Server Forums
 New to SQL Server Programming
 Assigning Multiple Values to Variable

Author  Topic 

robbied81
Starting Member

9 Posts

Posted - 2010-12-08 : 06:08:03
Hi,

I have about 20 INT values. I am querying a few tables and wanting to input values in a temp table.

My query is fine and works how I want with 1 INT value, but I don't want to have to run a query 20 times.

Basically I need to know how to assign 20 values and pass each value into my statement so it can input into my temp table.

Many Thanks in advance.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-08 : 06:11:42
Not sure what the question is.
Are you retrieving the int values from tables and want to know how to change the query to extract more than one value (in which case we'd need to know what the query looks like) or are you wanting to manually put 20 valusing into a temp table - if the latter then what is the issue with 20 insert statements?

==========================================
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.
Go to Top of Page

robbied81
Starting Member

9 Posts

Posted - 2010-12-08 : 09:36:35
Hi,

Here is an example. I have a room table with 50 rows. I only want details from 20 of them of which I will input details into a temp table. It is a bit more complex but I'm not worried about that yet.

So I want to have the 20 id's assigned to a variable and each one passed into the procedure

I.e

DECLARE @Variable INT,
SET @Variable = 1,2,3,4....

For each @Variable

INSERT INTO #TempTable(@variable, Name, Address, email)
SELECT @variable, Name, Address, email

I hope this is clear.

Thanks

Rob
Go to Top of Page
   

- Advertisement -