I am dynamically creating a BAT file to execute a series of bcp imports/exports. This has to be done dynamically, as I don't know the name of the tables until runtime.I have the following procedure that creates the first 2 sentences of the batch file:CREATE PROCEDURE dbo.CreateBATScript( @ServerName VARCHAR(100), @DatabaseName VARCHAR(100))ASSET NOCOUNT ONDECLARE @SQLCMD1 VARCHAR(MAX) , @SQLCMD2 VARCHAR(MAX) , @BATScript NVARCHAR(MAX)SET @SQLCMD1 = ' sqlcmd -S '+@ServerName+' -E -d '+@DatabaseName+' -Q "IF OBJECT_ID(''''dbo.NewStoreMapping'''',''''u'''')IS NOT NULL BEGIN DROP TABLE dbo.NewStoreMapping END;"'''-- Create first part of the script:SET @BATScript = 'SELECT ''@ECHO OFF'''-- DROPS & CREATES the dbo.NewStoreMapping tableSET @BATScript = @BATScript+'+CHAR(10)+'''+@SQLCMD1--SELECT @BATScriptEXEC (@BATScript)
I execute this procedure from the command line and output the results to a bat file (which will eventually contain all the bcp commands):SQLCMD -E -SWS23 -dsainsburys -Q "EXEC dbo.CreateBATScript 'WS23','sainsburys','D:\',NULL,NULL" -oD:\bcpscript.bat /h-1 PAUSE
However, all the results are appearing on the same line, even though I put a CHAR(10). What have I done wrong, or is this not possible?ThanksHearty head pats