Skip to content

Make -q and -i work together #389

Open
@shueybubbles

Description

@shueybubbles

Discussed in #206

Originally posted by 0x7FFFFFFFFFFFFFFF February 2, 2023
Right now, both sqlcmd and go-sqlcmd don't allow you to specify -q and -i options together. Below is the output of both commands.

c:\temp>sqlcmd -S . -E -q "SET PARSEONLY ON" -i test.sql
Sqlcmd: The i and the -Q/-q options are mutually exclusive.
c:\temp>sqlcmdgo -S . -E -q "SET PARSEONLY ON" -i test.sql
sqlcmdgo: error: --input-file and --initial-query can't be used together
c:\temp>

If this is possible, it will be very useful. In my case, I have a huge file test.sql that is not practical to open in SSMS. What I want is to check its syntax, just like what we normally do by clicking the Parse toolbar button in SSMS. What SSMS actually does is run the command SET PARSEONLY ON before your actually SQL code. If go-sqlcmd can allow us to execute a custom command and then an SQL file, it will basically allow us to parse huge SQL files without having to prepend the literal text SET PARSEONLY ON at the beginng of the file. This feature might be useful in some other cases, too. Hope you can consider adding this. Thanks.

Note there are 2 ways to accomplish the same result today, but they both require saving your boilerplate script to a file.

  1. Use multiple -i values and include your custom command file first
  2. Set the environment variable SQLCMDINI to the path of your custom command file and sqlcmd will run that script upon launch.

Enabling -q to work alongside -i would provide a more flexible solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions