×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Parsing Values Out of A URL Field

Parsing Values Out of A URL Field

Parsing Values Out of A URL Field

(OP)
Hi...

I have some data that contains a column with a URL field.  Within the URL field's contents, there are several values that I need to be able to parse out.  

I can only do this with SQL (i.e. cant write a function since I dont have permissions to register/execute).

Can anyone help?

Thanks!


Example of URL field data

WT.tz=-6&WT.bh=17&WT.ul=en-us&WT.cd=32&WT.sr=1280x720&WT.jo=Yes&WT.ti=Veda%20Spa%20at%20Hotel%20Monaco%20in%20Denver,%20Colorado&WT.js=Yes&WT.jv=1.3&WT.ct=lan&WT.hp=0&WT.bs=1263x1773&WT.fv=10.0&WT.slv=Unknown&WT.tv=9.3.0&WT.sp=KC-DMN&WT.dl=0&WT.ssl=0&WT.es=www.monaco-denver.com/veda-spa.html&WT.vt_f_tlh=1323388776&;WT.vtvs=1323385153721&WT.tsrc=Blazemore%20Hotels%20Properties&;WT.vt_tlh=1323388780&WT.co=Yes&WT.vt_sid=204.96.147.217-324432272.30190918.1323385158&WT.co_f=204.96.147.217-324432272.30190918

Example of final format/output of data

->One column for every WT parameter and its corresponding value

WT.tz  WT.bh  WT.ul  WT.cd  WT.sr    WT.jo  WT.TI
    6     17  en-us     32  1280x720   Yes  Veda Spa at Hotel Monaco in Denver,Colorado

RE: Parsing Values Out of A URL Field

Check out POSITION and SUBSTRING.

Are the different WT-labels always in this order? If that's the case it may end up with something like
SELECT SUBSTRING(col FROM POSITION('WT.tz=' IN col) + 6
                     FOR POSITION('WT.bh=' IN col) -
                         POSITION('WT.tz=' IN col) - 7) AS "WT.tz",
       SUBSTRING(col FROM POSITION('WT.bh=' IN col) + 6
                     FOR POSITION('WT.ul=' IN col) -
                         POSITION('WT.bh=' IN col) - 7) AS "WT.bh"
etc


You may also want to use CAST to reduce the length of the selected values.

RE: Parsing Values Out of A URL Field

(OP)
Hi JarlH,

Thanks for the snippet. When I tried to use, it gives me an error about a mismatched input around the "FROM" where it is expecting a ")" in the expression specification.  From this, I have tried to add the additional parenthesis but still get an error.  Sorry to be such a pain but can you review?

Thanks,

Tony

RE: Parsing Values Out of A URL Field

tony, the reason you're getting an error is likely because whatever database system you're using (which you didn't mention) doesn't support the ANSI SQL code that jarlh gave you

you do realize that you asked this question in the ANSI SQL forum, and not, for instance, in forum183: Microsoft SQL Server: Programming

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: Parsing Values Out of A URL Field

You could try the non-ansi
substring(arg1,arg2[,arg3])
or
substr(arg1,arg2[,arg3])
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close