I have a stored procedure that accepts a script and execute it against the database:
CREATE PROCEDURE [dbo].[usp_ExecuteScript]
@Script nvarchar(MAX)
AS
EXECUTE sp_executesql @Script;
When I call this procedure from command-line with sqlcmd Utility like:
sqlcmd -E -d <mydb> -Q "usp_ExecuteScript @Script=$(script)" /v script=my_script
where my_script is SELECT * FROM Users WHERE UserName ='John'
, I am forced to escape all special characters such as 'qoute' manually otherwise, it fails to execute.
This gets cumbersome when I am looping through a number of long and complex scripts to pass them as @Script argument to be executed this way.
Do you have any idea to get it work?