Avatar of jsuanque
jsuanque
Flag for Australia asked on

How to syntax of SQLCMD with output to a different server

Hello Experts,
Is it possible to have a sqlcmd invoked in Server1 and have a txt output to Server2? I was trying to do it but is getting an <Reason: The system cannot find the path specified>

SQLCMD -S DW04\DATA_ENTRY -i  \\Server2\inbox\MyTxtoutput.txt

...Maybe i'm just having a wrong sytax.
If possible, any suggestion would be appreciated.
Microsoft DOSMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
jsuanque

8/22/2022 - Mon
Qlemo

-i is for input. You want to use -o instead. And make sure you have access to that file from the box you are running sqlcmd on.
jsuanque

ASKER
Hello Qlemo,
Sorry it's using -o just mistyped it...

SQLCMD -S DRWNT-DW04\DATA_ENTRY -i C:\Apps\MySQL1.txt -o \\Server2\inbox\MyTxtoutput.txt
Alpesh Patel

First check to access from system directly using CLRL + R
IF not then Dos command will definitely give error. hence, first make it a network path.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
jsuanque

ASKER
Hello PatelAlpesh,
I could map the destination server from the source server. If this is what you meant, otherwise I'd appreciate the feedbaclk.
Qlemo

"from the source server" - Do you mean the MSSQL server you are connecting to with sqlcmd? That is useless - the file needs to be read by sqlcmd itself, which means the workstation.
ASKER CERTIFIED SOLUTION
jsuanque

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jsuanque

ASKER
I just thought that instead of two steps in batch file (which is my first option) there might be an easier or less step available.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jsuanque

ASKER
Different path was chosen as solution.