Split string into column

  • Please someone rescue me.  I have a string like this:

    'action=acct_zip&id=1B25B81JVJT&eid=FD05063&custnbr=281050&ky=FD05063&oc=$99 Free Shipping&mwn=&zip=90650&email=lafaithhome@yahoo.com'

    How can I use my select statement to split it up into 3 columns like this:

    Custnbr               Zip                 Email

    281050                90650             lafaithhome@yahoo.com

    My due date is today.  Please urgently help!

    Minh Vu

  • I set the string to a variable to help in the readability.

    Declare @String varchar(1000)

    set @String =

    'action=acct_zip&id=1B25B81JVJT&eid=FD05063&custnbr=281050&ky=FD05063&oc=$99 Free Shipping&mwn=&zip=90650&email=lafaithhome@yahoo.com'

    select substring(@String,(charindex('&custnbr=',@String) + 9), charindex('&', @String, (charindex('&custnbr=',@String) + 9)) - (charindex('&custnbr=',@String) + 9)) as custnbr,

           substring(@String,(charindex('&zip=',@String) + 5), charindex('&', @String, (charindex('&zip=',@String) + 5)) - (charindex('&zip=',@String) + 5)) as zip

           ,substring(@String,(charindex('&email=',@String) + 7), 250) as Email

    -- Results

    custnbr,zip,Email

    281050,90650,lafaithhome@yahoo.com

     

  • Fantastic!

    I really appeciate your help!

    Minh Vu

  • there's a bit of design issue here ;

    the web page that this querystring was posted to had all those values in the Request.Querystring collection in the name-value combinations you wanted, but instead of grabbing the portions of the string and saving them, the whole string was saved to your db instead; you should tweak that page to put the values into the proper columns instead of a "catch all" field that holds the whole querystring.

    your page should be grabbing Request.Querystring("CustNbr"), Request.Querystring("zip") and Request.Querystring("email")  and saving it to your db;

    here's a really simple way to see the name/value pairs:

    For Each Key in Request.QueryString

      Response.Write Key & ": " & Request.QueryString(Key) & "<BR>"

     Next

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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