Question

I've been playing around with SQLCMD to output a .SQL results to a file. It is working but the actual SQL statements are also being displayed in the output file which I obviously don't want. I am using a .bat file to run the SQL File. The following command is what I have in my .bat:

SQLCMD -S MyServerName -d MyDBName -i C:\test\start.SQL -o C:\test\out.txt -e

In my start.SQL I have the following:

set nocount on
    SELECT '<HEADER>', getDate(), '<HHEADER>'

SELECT UPPER(ACCTNUM), 
CONVERT(VARCHAR(10),DATEEXP,126),
UPPER(OPERID),
CONVERT(VARCHAR,CREATE_TMSTMP,120)

FROM RETURNS
WHERE CREATE_TMSTMP < getDate()
AND CREATE_TMSTMP > getDate() - 1


SELECT '<TRAILER>', getDate(), '<HHEADER>'

set nocount off

In the output file the correct information is shown but it's a little ugly with dashes and such and even shows the SQL command that was executed. Is there any way to fix this problem. Am I doing something wrong here? Any help would be greatly appreciated.

Was it helpful?

Solution

Why are you using the -e option?

-e Writes input scripts to the standard output device (stdout).

OTHER TIPS

The dashes are part of the header. Use -h-1 to specify no header. If that is not acceptable use something like FINDSTR /B /V "----" to exclude that header line... assuming none of the lines you want to keep start with dashes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top