SQLCMD question

  • i am using this below SQLCMD script to insert the output into a sql file which quires multiple servers (DiskMonitorServerList.txt).

    But the data is inserted only for the last server name mentioned in the text file.

    is below code correct?

    EX:

    DiskMonitorServerList.txt has

    BLALALALA

    BLALALAL\TEST

    the data is inserting only for BLALALAL\TEST server.

    MASTER..XP_CMDSHELL 'for /f %j in (D:\DiskMonitorServerList.txt) do sqlcmd -S%j -i D:\DiskMonitorCentralScript.sql > D:\DiskMonitorInsertScript.sql -UXXX -PXXX'

    Any help appreciated.

  • ranuganti (1/14/2015)


    i am using this below SQLCMD script to insert the output into a sql file which quires multiple servers (DiskMonitorServerList.txt).

    But the data is inserted only for the last server name mentioned in the text file.

    is below code correct?

    EX:

    DiskMonitorServerList.txt has

    BLALALALA

    BLALALAL\TEST

    the data is inserting only for BLALALAL\TEST server.

    MASTER..XP_CMDSHELL 'for /f %j in (D:\DiskMonitorServerList.txt) do sqlcmd -S%j -i D:\DiskMonitorCentralScript.sql > D:\DiskMonitorInsertScript.sql -UXXX -PXXX'

    Any help appreciated.

    Try:

    MASTER..XP_CMDSHELL 'for /f %j in (D:\DiskMonitorServerList.txt) do sqlcmd -S%j -i D:\DiskMonitorCentralScript.sql >> D:\DiskMonitorInsertScript.sql -UXXX -PXXX'

  • Thank you.. but this inserts duplicate records for the first server name..

  • Sorry.. the code works my bad i had duplicate servername is the txt file.

    Question: what if i have multiple servernames? do i need to use multiple >>>>?

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

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