0

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.

2 Answers 2

1

Why are you using the -e option?

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

Sign up to request clarification or add additional context in comments.

1 Comment

Added the nocount, took away the GO's, and took away that -e like you suggested and everything is clean. Thank you very much!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.