The following code works fine when executed directly in Sql server:
DECLARE @cmd sysname set @cmd = 'dir 'C:\A_Projects'' EXEC master..xp_cmdshell @cmd
but when I try to create a stored procedure as follows:
create procedure zz (@cmdin varchar(255)) EXEC master..xp_cmdshell @cmdin
I get a message
‘Incorrect syntax near the keyword ‘EXEC’.
Why?
1 Answer