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.
| Author |
Topic |
|
Pumkin
Starting Member
20 Posts |
Posted - 2005-09-27 : 10:43:59
|
| Hello guys..I have a problem here... I have a stored procedure with one parameter.And I want to call it in another stored procedure.The problem is that I don't cannot initialize the parameter unless I create a cursor that extracts the value for the parameter from a table.Does anyone know a better way to do this. A more efficient one maybe.Couldn't I just do something like this ..EXEC proc_name 'select param from table'Thank you |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-09-27 : 10:53:46
|
You could use dynamic sql to do this. Review this article right here on SQLTeam: [url]http://www.sqlteam.com/item.asp?ItemID=4619[/url]declare @param_name varchar(100), @cmd nvarchar(1000)select @param_name = 'Nathan'-- from yourTableset @cmd = 'usp_test ' + @param_name + ''Exec sp_executesql @cmd Nathan Skerl |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-28 : 00:56:51
|
| >>EXEC proc_name 'select param from table'This approach is not recommendedBe aware on theseEXEC proc_name 'Delete from table'EXEC proc_name 'Drop table table'MadhivananFailing to plan is Planning to fail |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-09-28 : 03:22:47
|
dsql is not recommended.you might want to review how you initialize that parameter, why do you need the cursor? is it not possible with set based approach?quote: Originally posted by Pumkin The problem is that I don't cannot initialize the parameter unless I create a cursor that extracts the value for the parameter from a table.
--------------------keeping it simple... |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-09-28 : 10:19:08
|
I COMPLETELY agree that dynamic sql is a last resort and comes with many performance and security compromises.We could just initialize the param as such:declare @param intselect @param = paramfrom tableexec proc_name @param Why wont this work Pumkin? Whats with the cursor?Nathan Skerl |
 |
|
|
|
|
|