| Author |
Topic |
|
cronincoder
Yak Posting Veteran
56 Posts |
Posted - 2006-02-02 : 14:14:02
|
| I've created a stored procedure that takes a parameter, example below:[CODE]create procedure @param1 intas select @param1 from db1[/CODE]This is what I don't know how to do: I want to get information for @param1 to pass to the stored procedure from a select statement, example:@param1 = select anumber from db1Can someone explain to me now I do this, and have it execute?thank you |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-02 : 14:23:33
|
| select @param1 = anumber from db1Tara Kizeraka tduggan |
 |
|
|
cronincoder
Yak Posting Veteran
56 Posts |
Posted - 2006-02-02 : 14:39:58
|
I get an error when I try that!create procedure @param1 intas select @param1 = anumber from db1, name from db1 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-02 : 14:47:47
|
| Why have you included ", name" in the code? Please post the error.Also, you need to pass @param1 into the stored procedure, not get the value while inside it.Tara Kizeraka tduggan |
 |
|
|
cronincoder
Yak Posting Veteran
56 Posts |
Posted - 2006-02-02 : 14:50:09
|
| Can you please tell me how I pass the parameter into the stored procedure? I believe that is what I don't understand-- exactly how to pass a parameter to a stored procedure. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-02 : 15:01:58
|
| Via Query Analyzer, it would be:EXEC StoredProcedureName @param1 = 'ValueToPassIn'Tara Kizeraka tduggan |
 |
|
|
cronincoder
Yak Posting Veteran
56 Posts |
Posted - 2006-02-02 : 15:05:04
|
| Tara,This is really the part that I don't quite get, I want to get many values to pass in. Can I do something along these linesEXEC StoredProcedureName @param1 = 'Select ValueToPassIn from db1'How do I populate the @param1 with the results of a query?cc |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-02 : 15:09:39
|
| If you are going to pass multiple values, then:http://www.sqlteam.com/item.asp?ItemID=11499Typically a parameter contains one value, but if you need multiples then you should pass them in comma separated. Then use that article for how to get the values out.Tara Kizeraka tduggan |
 |
|
|
cronincoder
Yak Posting Veteran
56 Posts |
Posted - 2006-02-02 : 23:34:22
|
How do you store the results from a call to another procedure into a local variable?declare @param varchar(1000)set @param = 'select info from Different Procedure' I tried executing a stored procedure which contained the code above and got the following error:Conversion failed when converting the varchar value 'select * from DifferentProcedure' to data type int.Is the code snippet above the correct way to retrieve information from a call to a stored procedure and store it in a local variable to use in a different stored procedure? |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-02-03 : 00:01:46
|
| Hi,You need to declare an output parameter in your Sp which is going to return a valueCreate Proc TestProc(@inparameter varchar(10), @outparameter varchar(100) output)asSelect @outparamer = column1 from tablewhere column2 = @inparameter---Now you can exucute the procedure asDeclare @inparam varchar(10)Declare @outparam varchar(100)set @inparam = 'Value1' -- setting value in input parameterexec testproc @inparam , @outparam outputprint @outparam -- output from procedureRefer BOL for more info |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-03 : 09:28:21
|
| If you want to use the result of a procedure to other procedure, thenCreate Procedure......asCreate table #t(......)Insert into #t(columns) EXEC yourProc...Then use that table to access data inside the procedureMadhivananFailing to plan is Planning to fail |
 |
|
|
|