Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:58:32+00:00 2026-05-17T02:58:32+00:00

I need to run a query against a legacy table that stores URL encoded

  • 0

I need to run a query against a legacy table that stores URL encoded text. I need this text to be decoded in my results. How do I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:58:33+00:00Added an answer on May 17, 2026 at 2:58 am

    Try one of these:

    CREATE FUNCTION dbo.UrlDecode(@url varchar(3072))
    RETURNS varchar(3072)
    AS
    BEGIN 
        DECLARE @count int, @c char(1), @cenc char(2), @i int, @urlReturn varchar(3072) 
        SET @count = Len(@url) 
        SET @i = 1 
        SET @urlReturn = '' 
        WHILE (@i <= @count) 
         BEGIN 
            SET @c = substring(@url, @i, 1) 
            IF @c LIKE '[!%]' ESCAPE '!' 
             BEGIN 
                SET @cenc = substring(@url, @i + 1, 2) 
                SET @c = CHAR(CASE WHEN SUBSTRING(@cenc, 1, 1) LIKE '[0-9]' 
                                    THEN CAST(SUBSTRING(@cenc, 1, 1) as int) 
                                    ELSE CAST(ASCII(UPPER(SUBSTRING(@cenc, 1, 1)))-55 as int) 
                                END * 16 + 
                                CASE WHEN SUBSTRING(@cenc, 2, 1) LIKE '[0-9]' 
                                    THEN CAST(SUBSTRING(@cenc, 2, 1) as int) 
                                    ELSE CAST(ASCII(UPPER(SUBSTRING(@cenc, 2, 1)))-55 as int) 
                                END) 
                SET @urlReturn = @urlReturn + @c 
                SET @i = @i + 2 
             END 
            ELSE 
             BEGIN 
                SET @urlReturn = @urlReturn + @c 
             END 
            SET @i = @i +1 
         END 
        RETURN @urlReturn
    END
    GO
    

    from http://sqlblog.com/blogs/peter_debetta/archive/2007/03/09/t-sql-urldecode.aspx


    CREATE FUNCTION dbo.fnDeURL
    (
        @URL VARCHAR(8000)
    )
    RETURNS VARCHAR(8000)
    AS
    BEGIN
        DECLARE @Position INT,
            @Base CHAR(16),
            @High TINYINT,
            @Low TINYINT,
            @Pattern CHAR(21)
    
        SELECT  @Base = '0123456789abcdef',
            @Pattern = '%[%][0-9a-f][0-9a-f]%',
            @URL = REPLACE(@URL, '+', ' '),
            @Position = PATINDEX(@Pattern, @URL)
    
        WHILE @Position > 0
            SELECT  @High = CHARINDEX(SUBSTRING(@URL, @Position + 1, 1), @Base COLLATE Latin1_General_CI_AS),
                @Low = CHARINDEX(SUBSTRING(@URL, @Position + 2, 1), @Base COLLATE Latin1_General_CI_AS),
                @URL = STUFF(@URL, @Position, 3, CHAR(16 * @High + @Low - 17)),
                @Position = PATINDEX(@Pattern, @URL)
    
        RETURN  @URL
    END
    

    from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=88926

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SP2007/MOSS I need to run a CAML query against a single list like
I am running this MySQL query against my db that contains a lot of
I need to run a RLIKE query on a database mmoved from MySQL to
What query do I need to run in PHP to get the structure of
I need to run an equipment audit and to do that I need to
I need to run a query on generated generated column names. Here's the query:
I need to run a JavaScript function onLoad(), but only do it if the
I need to run a stored procedure from a C# application. I use the
I need to run a Linux CLI command and get its stdout output from
I need to run a native program and retrieve the output in an Adobe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.