Wednesday, June 20, 2012

How to preserve the font style properties in SSMS

I had a requirement where i was asked to store the input data to be stored in the user font style format that we receive. we were asked to store data with font style like bold, italics, fonts with indicators like red or green, sentences with new line etc... to be stored as is. The challenge was t-sql always stores all the data in the standard format and there wasn't any way to store it with the styles. 

So one method which i have found is to store the data in the database with html tags: like '<b><font color="red">Worse</b></font>' as Column_A. 


You can store all the details from the client as html tags with in a table in the database for the later use. And when required we can pull the data through an external application.

For instance write the following query in your SSMS: 

SELECT ''<htmL><b><font color="green">Better</b></font></html>'' AS [Status]

Choose Result to File option (as shown in the screenshot)  in the tool pane.

Execute the query. 
A pop up window appears, specify the location where you want to store the file.
Store the result into a  .doc file.

The word "Better" is saved as bold green in color.

Note: If you store the file as .txt file, the result is saved as it is with the html tags.