Update to SQLCmdScriptExpander => is out

(Updated version available here)

As suggested by M Merrill in my former post of SQLCMDScriptExpander (which can be found here), I added an option for providing the encoding of files. So I created another option where you can specify the encoding from the following options:

/Encoding:[  ASCII |
                    BigEndianUnicode |
                    Default |
                    Unicode |
                    UTF32 |
                    UTF7 |
                    UTF8 ]

This will generate a file with the chosen encoding and will make sure that your special characters are honored. If no encoding is passed, it will fallback to the default value as of your settings on the machine. For more information, visit the encoding information page of MSDN here.

Thanks for the valueable input and feedback ! The new bits can be downloaded here.



Comments (6)

  1. Frank says:

    I was looking for a tool just like the one you wrote. I find the lack of this functionality in sqlcmd a big disappointment.

    I tried your tool and I found some issues. The first three very very minor.

    1.- In the help usage OutputfFile has two 'f's.

    2.- Every time i run it if the output file exists it appends to it.

    3.- I must explicitly specify an encoding when you have a default one.

    4.- I was really expecting to have the :setvar VarName "VarValue" to be also found and replaced properly in the outputfile.

    Your previous post implies that your tool :

    "In addition, the executing person needs to have a command line interpreter (like SQLCMD) capable of understanding the syntax of :r to pickup the referenced files".

    If you could fix at least the last one, it would be appreciated.


  2. Hi Frank,

    thanks for the Feedback. To the points:

    1. Thanks for reporting, I will fix that.

    2. I understand that this does not make sense in most cases, will recreate the file instead.

    3. That seems to be a bug which I will also fix.

    4. Replaced with what actually ? The replacement would have to be done on runtime of the script. A script can be e.g. ´called with SQMCMD, there you have the -v command to pass in values for parameters. I didn not want to copy any existing functionality, just add missing functionality in my tools. So here is how I use it and what I suggest you.

    -Expand the files with the ScriptExpander tool.

    -Once being expanded, call the created script from SQLCMD and use the -v Switch to pass in parameters.

    For the other things, watch out the next Version which I will tag as the Frank Edition 😉


  3. Andrew says:

    This does not appear to support ( characters in the file name referenced by the :r command

  4. Brett Gerhardi says:

    This is a really great tool. I am trying to use this to help build Pre and Post Ssdt scripts for feature/versions in ssdt along with a build / deploy server

    1. However it doesn't allow me to use all my files as they are currently.

    I get errors during execution that it cant find the files (although sqlcmd executes them in-place fine).

    I get comment in the file like:

    Start of content from script file 'F:SvnRootxxxxxxyyyyyyyyyTrunkDbDeploy – Versionv02.005Scripts……Deploy '

    But this is truncated, this is not the whole path

    2. Even when I have these errors, I get the errors listed in the scrolling output but at the end it still says Processing of file…. completed successfully and returns an errorlevel of 0 which is dangerous as the outer process will not know that there is an issue.

    I'd be grateful if these issues could be resolved (unless there are already further updates somewhere)

    It would also be great if you could share the source somewhere so we could improve over time as a community.


  5. JensSuessmeyer says:

    Hi, and thanks for the feedback. Wow this is a really old piece of code 🙂 Let see if a can reassemble the pieces again.I don´t have any exhaustive loggging in the solution but I will take a look at the error outlined and let you know.

  6. Brett Gerhardi says:

    Hi Jens, after further investigation this seems to be similar to Andrew's case where there are some valid characters that the code is not dealing with (in my case it seems to be a hyphen).

Skip to main content