Unicode to ASCII table

  • Hi,

    To have an application running on multi language, I got stuck on the following problem. I have a master text library in unicode using a table with column type nvarchar. To synchronize this table with another application I have to convert this table to ASCII (column type varchar) by using a codepage and use this same codepage later on to show the texts in the application as they are in unicode.

    Does anyone have a suggestion how to do this?

    Thanx,

    Pieter

  • This was removed by the editor as SPAM

  • I don't think there is anything built-in to SQL Server that does this, so you'll need to write some code to do it.

    I've been playing around with this CLR UDF and it might help you out if you're using SQL Server 2005.

    1. Create a new class library add something like this:

    using System;

    using System.Text;

    using Microsoft.SqlServer.Server;

    using System.Data.SqlTypes;

     

    public class TextEncodingUtility

    {

        [SqlFunction(DataAccess = DataAccessKind.None)]

        public static SqlString Convert(SqlString inputText, SqlString fromEncodingName, SqlString toEncodingName)

        {

            byte[] pts = Encoding.GetEncoding(fromEncodingName.Value).GetBytes(inputText.Value);

            return (SqlString)Encoding.GetEncoding(toEncodingName.Value).GetString(pts);

        }

    }

     

    2. Register the assembly (.dll) with SQL Server (where X is the path where the dll is located)

    CREATE

    ASSEMBLY [Utils]

    FROM 'X:\TextEncodingUtility.dll'

    3. Link up the SQL UDF

    CREATE FUNCTION dbo.ConvertTextEncoding

    (

      @inputText NVARCHAR(MAX),

      @fromEncodingName NVARCHAR(100),

      @toEncodingName NVARCHAR(100)

    )

    RETURNS NVARCHAR(MAX)

    AS EXTERNAL NAME Utils.TextEncodingUtility.[Convert]

     

     

  • Thank you for your reply! However I have the slight problem that I do not have .NET available so I have to find another way.

    Cheers,

    Pieter

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply