How to remove Scripting variables not defined in sqlcmd

  • I've been executing the SQL script in sqlcmd and it has more arguments.

    Is there any possibility to declare some of the arguments as optional, If user fails to enter value for any of the arguments then it displays the following message.

    **

    'inputvar1' scripting variable not defined

    'inputvar2' scripting variable not defined

    'inputvar3' scripting variable not defined

    **

    And, the following statement get printed along with above message

    Changed database context to 'testdb'

    I need to remove these messages while getting printed in output file.

    Please help me on t

  • Can anyone help me on this?

  • are you explicitly defining the variables by using the :Setvar command?

    Gerald Britton, Pluralsight courses

  • No, I'm just passing arguments by using -v inputvar1="abc" inputvar2="xyz".

    Here, user may pass argument called "inputvar3". If user fails to enter "inputvar3" then it's printing the message like 'inputvar3' scripting variable not defined

    I don't want to print the message like if fails to pass arguments "inputvar3"

  • I know I'm coming along late on this thread, but you can use the following:

    SQLCMD -S YourServer -E -d YourDatabase -i YourScript 2> nul

    That will send the StdErrorOut to the bit bucket.

  • dsacker wrote:

    I know I'm coming along late on this thread, but you can use the following:

    SQLCMD -S YourServer -E -d YourDatabase -i YourScript 2> nul

    That will send the StdErrorOut to the bit bucket.

     

    I am facing the similar issue and i will follow the mentioned instructions and update you here. Thank you for your help

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply