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 |
|
rohitgraycell
Starting Member
8 Posts |
Posted - 2006-04-21 : 05:20:11
|
| I am executing a stored procedure from within other procedure with EXEC SPname Command. I have read that we should use sp_ExecuteSql system stored procedure in place of EXEC command because it will catch the execution plan whereas executing a statement or a stored procedure will not catch the execution plan. Now i am trying to execute my stored procedure as Execute Sp_ExecuteSql @parameterName from within another stored procedurewhere @paramter is an integer (but internet says that sp_executesql only accepts nvarchar/ntext datatype).So i am not able to really execute my stored procedure with sp_ExecuteSql. Am i missing out something..is there some prodedure to do this task???ANY HELP WILL BE GREATLY APPRECIATED.THANKS |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-21 : 05:28:07
|
please do not cross post.You can look up SQL Server Books Online for more information on sp_executesql.sp_executesql can accept multiple parameters not limited to varchar or nvarchar. quote: sp_executesql [@stmt =] stmt[ {, [@params =] N'@parameter_name data_type [,...n]' } {, [@param1 =] 'value1' [,...n] }]Arguments[@stmt =] stmtIs a Unicode string containing a Transact-SQL statement or batch. stmt must be either a Unicode constant or a variable that can be implicitly converted to ntext. More complex Unicode expressions (such as concatenating two strings with the + operator) are not allowed. Character constants are not allowed. If a constant is specified, it must be prefixed with an N. For example, the Unicode constant N'sp_who' is legal, but the character constant 'sp_who' is not. The size of the string is limited only by available database server memory.stmt can contain parameters having the same form as a variable name, for example:N'SELECT * FROM Employees WHERE EmployeeID = @IDParameter'Each parameter included in stmt must have a corresponding entry in both the @params parameter definition list and the parameter values list.[@params =] N'@parameter_name data_type [,...n]'Is one string that contains the definitions of all parameters that have been embedded in stmt. The string must be either a Unicode constant or a variable that can be implicitly converted to ntext. Each parameter definition consists of a parameter name and a data type. n is a placeholder indicating additional parameter definitions. Every parameter specified in stmt must be defined in @params. If the Transact-SQL statement or batch in stmt does not contain parameters, @params is not needed. The default value for this parameter is NULL.
only the @stmt and @params need nvarcharyou can pass in integer parameter for exampledeclare @var1 int, @var2 varchar(10)exec sp_executesql @sql, N'@var1 int, @var2 varchar(10)', @var1, @var2 KH |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-04-21 : 05:28:45
|
the "internet" is correct,also, interpretation of what you're trying to doexecute the sproc sp_executesql that will execute @parametername which is an integer?exec 1?you need the rest of the query not just the parameter --------------------keeping it simple... |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-04-21 : 06:30:36
|
| "please do not cross post"Damn! Didn't see this, so I've answered it in the other posthttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65059 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-21 : 08:07:02
|
my fault. Next time i will use bigger font KH |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-04-21 : 08:12:37
|
| Nah, I started my post before you got there, and then the phone rang ... |
 |
|
|
|
|
|
|
|