Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use a select statement to get parameters for stored procedure

Status
Not open for further replies.

AnnaWnz

MIS
Dec 10, 2002
22
0
0
NZ
Hi

I am trying to run a stored procedure that requires four value be fed into it, but I don't want to use fixed values, but use values from a table instead and am not sure how to write this out.

what I have written is:

select value1, value2, value3, value4 from #TEMP1
EXEC stored_procedure value1, value2, value3, value4

The values in the select don't seem to flow into the EXEC statement. what am I missing?? Do I need to assign the the fields to the parameters?

Thanks

Anna

 
You have to declare variables to use

Try something like this, but make sure you change the datatypes to suit your values

DECLARE @value1 INT
DECLARE @value2 VARCHAR(1000)
DECLARE @value3 VARCHAR(100)
DECLARE @value4 varchar(100)

DECLARE ValueCursor CURSOR FORWARD_ONLY FOR
select value1, value2, value3, value4 from #TEMP1
OPEN ValueCursor

FETCH NEXT FROM ValueCursor INTO @Value1, @Value2, @Value3, @Value4
EXEC stored_procedure @value1, @value2, @value3, @value4

CLOSE ValueCursor
DEALLOCATE ValueCursor

Transcend
[gorgeous]
 
Hi Transcend

I have tried that - I don't get any errors, but I still get no results. It's still like the values being passed are not being picked up by the stored procedure correctly?? Any ideas?

Anna
 
What happens when you run this in query analyser?

select value1, value2, value3, value4 from #TEMP1

do you get any results?

Transcend
[gorgeous]
 
Hi Transcend

When I run that line I get what I expected, which is why I'm confused that the code you gave me doesn't work.

Hang on, think I've got it working now - something to do with the data not the script, shall have to do some more testing but shall post result!

Thanks for your help.

Anna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top