2

Using SQLCMD, I am running a script to output to STDOUT then gziping the output. When I look at the output file, I see this warning message:

Database name 'tempdb' ignored, referencing object in tempdb.

In my script, I have a check at the start of the script to drop the temp table if it exists:

IF OBJECT_ID('tempdb..#TheTable') IS NOT NULL
BEGIN
    DROP TABLE tempdb..#TheTable
END

However - I have also SET NOCOUNT ON, but file still captures the warning message.

SQLCMD Script:
sqlcmd -i TheScript.sql -h-1 -k1 -s"," -W -u | gzip > "C:\TheOutput.gz"

Is there a way to suppress a message like that?

2 Answers 2

2

Change your if condition to the following pattern:

IF 0 < OBJECT_ID('tempdb..#TheTable')
 DROP TABLE #TheTable

This should not result in any error messages.

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

Comments

0

Simple clean version that works on SQL Server 2016 and above without any messages:

drop table if exists #TheTable

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.