February 6, 2006 at 5:59 pm
Within a procedure that I exec, there is a varchar that is included as one of the parameters. I am using the following to code to execute the procedure "usp_MyProc" which has 2 parameters @SchID int and @UpdatedBy varchar(39).
SET @mySQL = 'usp_MyProc'+convert(nvarchar(20), @SchoolID)+', '+char(39)+'DATA IMPORT'+char(39) EXEC (@mySQL)
Thanks,
John
February 6, 2006 at 6:39 pm
Not really! But the other alternatives (apart from char(39) that you've used) include QUOTENAME() and to double the single quote.
February 6, 2006 at 9:28 pm
Hi John,
You could use sp_executeSQL and pass your parameters in separately, withoug worrying about the extra enclosing quotes...
SET @mySQL = N'EXEC usp_MyProc @SchID, @UpdatedBy'
SET @params = '@SchID nvarchar(20), @UpdatedBy nvarchar(20)'
SET @paramSchID = Convert(nvarchar(20),@SchoolID)
EXEC sp_executesql @mySQL, @params, @paramSchID, 'DATA IMPORT'
February 8, 2006 at 7:42 am
SET @mySQL = 'usp_MyProc ' + Convert(nvarchar(20), @SchoolID) + ', ''' + 'DATA IMPORT' + ''''
--or--
SET @mySQL = 'usp_MyProc ' + Convert(nvarchar(20), @SchoolID) + ', ' + '''' + 'DATA IMPORT' + ''''
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply