January 14, 2015 at 2:15 pm
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.
January 14, 2015 at 2:23 pm
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'
January 14, 2015 at 2:28 pm
Thank you.. but this inserts duplicate records for the first server name..
January 14, 2015 at 2:31 pm
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