Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005

    Question Unanswered: command line and insert

    I'm trying to insert into a table 2 values one of which is an

    exec master..xp_cmdshell @command where I have assigned @command with a value

    this statement gives me the result into a 1 col. table fine:

    insert into mytable99(col1) exec master..xp_cmdshell @command

    now what I want to do is put col2 in there as well!!

    ie. insert into mytable99(col1,col2) values (exec master..xp_cmdshell @command, '123')

    I get a sytax error ... on the exec ??

    Could anyone help re the proper way of doing this ... thanks in advance

  2. #2
    Join Date
    Jan 2003
    Nottinghamshire, UK
    did'nt know U could do something like this - sounds possibly clever

    Syntax wise this command expects the optional parameter no_output after the comma

    xp_cmdshell {'command_string'} [, no_output]

    Your probably better off with with assigning each value to a local variable then inserting the contents of the variables into the table - something like

    SET @CmdShellOutput = exec master..xp_cmdshell @command
    SET @StringNumber = '123'

    insert into mytable99(col1,col2)
    values (@CmdShellOutput , @StringNumber)

    Sorry not had time to test this syntax but hopefully U get the picture.

    "Everything should be made as simple as possible, but not simpler." - Albert Einstein
    "Everything should be made as complex as possible, so I look Cleverer." - Application Developer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts