SQL Server UrlEncode

Source: Internet
Author: User
Tags urlencode

SQL Server UrlEncode

if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ UrlEncode] ') and xtype in (n ' FN ', n ' IF ', n ' TF ')--delete the function drop functions [dbo]. [UrlEncode] Gocreate FUNCTION dbo. UrlEncode (@URL varchar (3072)) RETURNS varchar (3072) asbegin DECLARE @count int, @char varchar (2), @i int, @bytes binary (2), @low8 int, @high8 intdeclare @URLEncode varchar (3000); Set @count = LEN (@URL) Set @i = 1SET @URLEncode = "while (@i <= @count) BEGIN SET @char = SUBSTRING (@URL, @i,1) IF @char Like ' [-a-za-z0-9 () ' *._!] ' and datalength (@char) = 1 Set @URLEncode = @URLEncode + @char ELSE begin IF Datalength (@char) = 1 begin SET @URLEncod E = @URLEncode + '% ' + SUBSTRING (' 0123456789ABCDEF ', (ASCII (@char)/+ 1), 1) SET @URLEncode = @URLEncode + SUBSTRING ('  0123456789ABCDEF ', (ASCII (@char)% + 1), 1) END ELSE BEGIN Set @bytes = CONVERT (binary, @char) Set @high8 = (0xff00 & Cast (@bytes as int))/256 Set @low8 = 0x00FF & CAST (@bytes as int) Set @URLEncode = @URLEncode + '% ' + SUBST RING (' 0123456789ABCDEF ', (@high8/16 + 1), 1) Set @URLEncode = @URLEncode + SUBSTRING (' 0123456789ABCDEF ', (@high8% + 1), 1) Set @URLEncode = @URLEncode + '% ' + SUBSTRING (' 0123456789ABCDEF ', (@low8/16 + 1), 1) SET @URLEncode = @URLEncode + SUBSTRING  (' 0123456789ABCDEF ', (@low8% 16 + 1), 1) End end SET @i = @i + 1 END RETURN @URLEncode; END

SQL Server UrlEncode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.