SQLCMD Syntax

Mauro Cazabonnet
Mauro Cazabonnet used Ask the Experts™
on
I'm trying to run a sqlcmd as follows

If I append say PRINT 'TEST' to the @command it errors out

What am I missing?

DECLARE  @command VARCHAR(256) 
DECLARE  @CommandText VARCHAR(512) 
DECLARE  @SQLCMD VARCHAR(64) 

SET @SQLCMD = 'SQLCMD -SLocalHost -E -Q ' 
SET @command = ':CONNECT SERVER1' 

SET @CommandText = @SQLCMD + '"' + @command + '"' 
PRINT @CommandText 

EXEC MASTER.dbo.Xp_cmdshell @CommandText

GO 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .NET Software Engineer
Top Expert 2015
Commented:
This @command doesn't work

SET @command = ':CONNECT SEVER1 :OUT STDOUT'
Mauro CazabonnetSenior .NET Software Engineer
Top Expert 2015

Author

Commented:
Never mind I can specify the remote server and database as a parameter in sqlcmd :)

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