Welcome to my ASP Code Website

MSSQL and Character Set Issues

One of the most troubling parts of ASP and SQL for new programmers can be how to handle apostrophes and other special characters. Here is a guide to getting those apostrophes working properly. First, we have to understand a few basic concepts.

When you look at the definition of your tables in the MSSQL admin area, the extended properties will tell you how each table was initialized. You might see values like Collation: SQL_Latin1_General_CP1_CI_AS. What is a collation, and what does it have to do with a character set?

A collation is a set of rules about how things represented by a character set - letters, numbers, symbols, and so on - are sorted. So a collation is NOT a character set. It is simply a set of rules.

So what you really want to think about is how the browser window itself is handling the characters it's retrieving from and sending to the database. In the old days, that character set might have been ISO-8559-1. However, in modern times the standard for character sets is UTF-8. That's because UTF-8 covers a huge range of characters in all languages, so you're ready for anything.

To ensure your browser window is set to retrieve and send characters in UTF-8, you'd add this code to the top of your page. Right at the very top.

<%@ Language=VBScript CodePage = 65001%>
Session.CodePage = 65001
Response.charset ="utf-8"
Session.LCID = 1033 'en-US

And then in the HEAD area you have your normal line of:

<meta charset="UTF-8"%>

Ask with any questions!

Inserting Into a Database with ASP

To learn more about the basic syntax options for a select statement, read Syntax of a SQL Select Statement.

Basics of SQL Commands