Percent Encoding (also known as URL Encoding) is a technique for encoding the values in strings that are not able to be directly represented, according to the rules for the target location. For example, not all characters are permitted in URLs.
Percent encoding a T-SQL string is also useful when working with XML. For example, one common method for splitting strings is based on the use of XML PATH but if you try to use those types of string splitters with strings containing, say, percent signs, you'll find they just don't work.
One of our free SDU Tools for SQL Server DBAs and developers is PercentEncode. It can perform the encoding for you. It is based on this Wikipedia PercentEncoding article:
It conforms with RFC 3986 (https://tools.ietf.org/html/rfc3986) and so it encodes all characters apart from the following
- A to Z
- a to z
- 0 to 9
You can see an example of it in the image above, and you can see it in action here:
You'll find more information about our free SDU Tools here: