[dba-SQLServer] Passing variable to xp cmdshell

Paul Hartland paul.hartland at googlemail.com
Wed Apr 15 03:32:24 CDT 2009


To all,

I am having a problem using xp cmdshell in SQL Server 2005, I won't go into
too much detail but basically I am just trying to put a folder list into a
temporary table.

if I use exec master..xp cmdshell 'dir "myserver\myinitialfolder" /b'  it
works fine, however I need to generate the folder on the fly, but if I
declare a variable say @folder varchar(4000) and then have exec master..xp
cmdshell @folder I get

Msg 214, Level 16, State 201, Procedure xp cmdshell, Line 1
Procedure expects parameter 'command_string' of type 'varchar'.

Anyone any ideas whats happening, or what I am doing wrong ?

Thanks is advance for any help on this.

-- 
Paul Hartland
paul.hartland at googlemail.com



More information about the dba-SQLServer mailing list