Need T-SQL UDF to URLEncode non-Ascii characters (i.e. Chinese, Macedonian, etc)

Posted on 2012-09-04
Medium Priority
Last Modified: 2012-09-10
We need a function that will properly url encode a string even if it contains non-ascii characters such as chinese language characters for example.

We've tried this already:

Along with this:

And they don't handle non-ascii characters well.  If this can't be done in t-sql can someone post or recommend some good VB.Net or C# code that we can turn into a dll and upload to the db?
Question by:afacts
LVL 19

Accepted Solution

Rimvis earned 2000 total points
ID: 38366755
Hi afacts,

Second function (http://sqlblog.com/blogs/peter_debetta/archive/2007/03/09/t-sql-urlencode.aspx) should handle unicode characters. Make sure you are passing parameter as NVARCHAR, not VARCHAR. You should put N before string value, like this:

SELECT dbo.UrlEncode(N'¿¿/¿¿')

Author Closing Comment

ID: 38383698
Thanks Rimvis ... we decided to go a different route in functionality but you're right in that, that function is actually better than the others when used correctly ...

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question