xp_cmshell

  • Please help.  I'd like this to be achieved.

    exec dmi_sp_ftp

     'inventory.txt',

     'f:\data_dump\emer',

     'inventory.txt',

     'EMER/INV',

     '133.127.2.694',

     'rmvu',

     '#mcs!23,

     'get',

     0,

     'ascii'

    declare @cmd varchar(1000)

    declare @filename varchar(100)

    declare @dt smalldatetime

    set @dt = getdate()

    set @filename = 'F:\data_dump\emer\archive\inventory_' +

    cast(year(@dt) as varchar(4)) +

    right('0' + cast(month(@dt) as varchar(2)),2) +

    right('0' + cast(day(@dt) as varchar(2)),2) + '_' +

    right('0' + cast(datepart(hh,@dt) as varchar(2)),2)  +

    right('0' + cast(datepart(mm,@dt) as varchar(2)),2)  +

    '.txt'

    set @cmd = 'copy F:\data_dump\emer\inventory.txt  + @filename

    EXEC master.dbo.xp_cmdshell @cmd

    The problem is with my set @cmd.  It is incorrect syntax.  It should be:

    set @cmd = 'copy F:\data_dump\emer\inventory.txt  @filename'

    However I couldn't put my parameter in the quote.  Is there anyway to overcome this?

    Thanks

    Minh Vu

     

  • you mean this?

    set @cmd = 'copy F:\data_dump\emer\inventory.txt ' + @filename

  • I tried that too, but it is not correct syntax.  I meant something like this.  set @cmd = 'copy F:\data_dump\emer\inventory.txt  @filename'

    But like I said, I couldn't put parameter in quotes.

     

    Minh Vu

  • Declare @FileName as varchar(200)

    set @FileName = 'C:\Whatever.txt'

    select 'copy F:\data_dump\emer\inventory.txt ' + @filename

    --copy F:\data_dump\emer\inventory.txt C:\Whatever.txt

    select 'copy F:\data_dump\emer\inventory.txt ''' + @filename + ''''

    --copy F:\data_dump\emer\inventory.txt 'C:\Whatever.txt'

    select 'copy F:\data_dump\emer\inventory.txt "' + @filename + '"'

    --copy F:\data_dump\emer\inventory.txt "C:\Whatever.txt"

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply