Wednesday, June 1, 2011

How to save a SSMS result set with ANSI Encoding

It is a common practice for DBAs and Database Developers to save SSMS(SQL Server Management Studio) query results to CSV files. Most of the time the purpose of this is to use the CSV file in another 3rd party application.

The easiest way to do this is by selecting the whole results set in the results window and right clicking on it and then selecting Save Result As option. This will pop up a window to name the output file, in the file name text box enter the CSV file name and you can save the results to a CSV file without any hassle.

The problem is when you save it like this the output files encoding type is UNICODE. It is perfectly fine if you are processing the file in SQL Server itself.  But I have seen many other 3rd party applications still doesn’t support UNICODE character encoding. So we have to save the files with commonly supported encoding type such as ANSI.

You can do this by following the same process and when the Save dialog box appears enter the CSV name and instead of clicking on the Save button, click on the small down arrow on the Save button;

Then select Save with Encoding option. It will popup the below screen.



In this screen select Ansi from the drop down list of available encodings. Then Ok and click Save on the Save dialog box. Now the CSV is saved with Ansi Encoding instead of UNICODE.

No comments:

Post a Comment