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 |
mksdf
Starting Member
26 Posts |
Posted - 2014-10-02 : 05:30:52
|
can you execute an execute statement? I am getting an error. What is the way around this?For exampleDECLARE @SQL nvarchar(MAX)DECLARE @DB nvarchar(100) = 'DB_TEST' , @ID int = 1SET @SQL = 'EXEC ' + @DB + '.dbo.usp_test ' + CAST(@ID AS varchar(4))EXEC @SQL Thanks |
|
MichaelJSQL
Constraint Violating Yak Guru
252 Posts |
Posted - 2014-10-02 : 07:21:16
|
Try the following : DECLARE @SQL nvarchar(MAX)DECLARE @DB nvarchar(100) = 'DB_TEST' , @ID int = 1SET @SQL = 'EXEC ' + @DB + '.dbo.usp_test ' + CAST(@ID AS varchar(4))EXEC SP_EXECUTESQL @SQLI ran this to confirm no issues because I don't have your procDECLARE @SQL nvarchar(MAX)DECLARE @DB nvarchar(100) = 'master' , @ID int = 1SET @SQL = 'EXEC ' + @DB + '.dbo.sp_helpfile ' EXEC SP_EXECUTESQL @SQL |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-10-02 : 19:35:57
|
exec (@SQL) No amount of belief makes something a fact. -James Randi |
|
|
|
|
|