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.
- Use multiple
-i values and include your custom command file first
- 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.
Discussed in #206
Originally posted by 0x7FFFFFFFFFFFFFFF February 2, 2023
Right now, both
sqlcmdandgo-sqlcmddon't allow you to specify-qand-ioptions together. Below is the output of both commands.If this is possible, it will be very useful. In my case, I have a huge file
test.sqlthat 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 commandSET PARSEONLY ONbefore your actually SQL code. Ifgo-sqlcmdcan 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 textSET PARSEONLY ONat 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.
-ivalues and include your custom command file firstSQLCMDINIto the path of your custom command file and sqlcmd will run that script upon launch.Enabling
-qto work alongside-iwould provide a more flexible solution.