How to syntax of SQLCMD with output to a different server

jsuanque
jsuanque used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
-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.

Author

Commented:
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 PatelSolution Architect at TCS (SAFe®Agilist, TOGAF® Foundation, PSM I®, MCP, MCSD)

Commented:
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.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
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"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
"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.
Commented:
Don't bother guys. I guess I'll go to my first option that works which is...
run sqlcmd and dump the output file to same server then do a xcopy to my final or desired derver.

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

XCOPY C:\Apps\MyTxtoutput.txt \\Server2\inbox\

Author

Commented:
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.

Author

Commented:
Different path was chosen as solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial