Select specific part of the string

  • Hi all

    I have got column in my database which stores referral url.

    sample values in table ie:

    http%3a%2f%2fwww.test.co.uk%2fApp.aspx%3f

    http://www.test.com

    test.com

    Google

    I need to write query which would only return domain name (test.com or GOOGLE) regardles what is before or after that.

    Ro

  • 1. Look for the string // (of http://). If you find it, the character that comes after it is your starting position. If you don't find it, the starting point is the first character of the string.

    2. Look for the character / in the string that comes after the starting point found in step 1 (so that you exclude http://). If you find it, the end point is the character that comes right before this position. If you don't find it, the end point is the last character of the URL.

    3. Take a substring between the points you found in step 1 and step 2.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks for your reply,

    any chance to write query for me as I am only beginner with SQl querying. I am only learning and not familiar with how to work with strings in sql.

    Thanks

  • You'll learn a lot more if you try to write the query yourself.

    Take a look at the following functions:

    CHARINDEX

    SUBSTRING

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

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

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