Thursday, March 29, 2007

xp_cmdshell

Why is it that you can pass a built string to xp_cmdshell but you can't build your string at the same time. What I mean is this:
This is legal:
DECLARE @cmd VARCHAR(255)DECLARE @ServerName SYSNAME
SET @ServerName = 'Server1'SET @cmd = 'copy C:\temp\test.txt \\ + @ServerName + '\SomeShare\'
EXEC master.dbo.xp_cmdshell @cmd

No comments: