Link to home
Avatar of Mauro Cazabonnet
Mauro CazabonnetFlag for United States of America

asked on

SQLCMD Syntax

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

ASKER CERTIFIED SOLUTION
Avatar of Mauro Cazabonnet
Mauro Cazabonnet
Flag of United States of America image

Blurred text
THIS SOLUTION IS 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
Avatar of Mauro Cazabonnet

ASKER

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