Monday, November 12, 2012

SQL Server Unicode and Codepage Support




STEP 1: Find all your collations...



CREATE TABLE #CollationTbl
(ID INT Identity (1,1),ServerCollation sql_variant, DatabaseName varchar(300),    DatabaseCollation sql_variant ,    DatabaseCollationDescription nVarchar(500))

EXEC sp_MSforeachdb


'

Declare
    @1 sql_variant = (SELECT SERVERPROPERTY(''Collation''))
    ,@2 varchar(300) = "?"
    ,@3 sql_variant = (SELECT DATABASEPROPERTYEX("?",''Collation''))
    ,@4 varchar(300)
   
    SET @4 = (SELECT DESCRIPTION FROM fn_helpcollations() WHERE Name = @3)



INSERT INTO #CollationTbl
SELECT @1 , @2, @3, @4
    ;
   
'

SELECT * FROM #CollationTbl;

DROP TABLE #CollationTbl;

STEP 2: Look at each element of the collation. The code page element should be the same or lower page than the code page set in the OS.

The OS codepage can be found using

C:>systeminfo|findstr -i locale
System Locale:             en-us;English (United States)
Input Locale:              N/A

You can also try using chcp, but it really defines the codepage used in the command prompt session, not the codepage for the server. This is useful for debugging character/codepage incompatibility.

C>chcp
Active code page: 437

References
http://msdn.microsoft.com/en-us/library/ms143726%28v=sql.105%29.aspx
http://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using
http://msdn.microsoft.com/en-us/library/ms186356%28v=sql.105%29.aspx

No comments:

Post a Comment