Saving an Sql Script in a Different Encoding

In some situations I create scripts and store them in a folder. Later I will concatenate the contents using a batch file which doesn’t work very well if the files do not use the same encoding.If you have one in Codepage 1200 and another in Codepage 1252 then you will have some very odd characters in your resulting script

When writing a script in Sql Server Management Studio, you can save them with different encoding. I learnt the idea of a previous employee at work and found it useful.

By default Management Studio seems to want to save new scripts (press “New Query” button) as “Western European (Windows) – Codepage 1252”, yet when you click “Modify” to edit a stored procedure, for example, and then try and save the script it will, by default, save as “Unicode – Codepage 1200″… and these don’t concatenate together very well as already explained.

There seems to be know way within Management Studio to set a default for this, so unless I’m mistaken, we are stuck doing things manually. Here is how:

When you have the Save File dialog, click the little drop down box at the right of the “Save” button, and click “Save with Encoding…” option.

Sql Management Studio - Save with Encoding...

Sql Management Studio - Save with Encoding...

You can now select the type of encoding.

I had done a fair bit of work with Management Studio before I came across this small drop down on the save button. It’s not really obvious as I was expecting a drop down box on the actual dialog. Hopefully this will be helpful to someone else also.

Advertisements

One Response to “Saving an Sql Script in a Different Encoding”

  1. Concatenating Sql Scripts « What to call it? Says:

    […] Saving an Sql Script in a Different Encoding […]


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: