Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would do this to extract the text:</p> <pre><code>DECLARE @URL VARCHAR(4000) SET @URL = 'http://start.mysearchdial.com/results.php?q=hovercrafting+manchester&amp;category=web&amp;a=coolmsd&amp;f=2&amp;cd=2&amp;XzuyEtN2Y1L1QzuyEzzyD0&amp;cr=1818627175&amp;uref=14&amp;start=1' DECLARE @QSXML xml SET @QSXML = CAST('&lt;a&gt;&lt;b&gt;' + REPLACE(SUBSTRING(@URL,CHARINDEX('?',@URL)+1,4000),'&amp;','&lt;/b&gt;&lt;b&gt;') + '&lt;/b&gt;&lt;/a&gt;' as xml) select SUBSTRING(c.value('.','varchar(4000)'),4,4000) from @QSXML.nodes('/a/b') t(c) where c.value('.','varchar(4000)') like 'cd=%' </code></pre> <p>The reason I'd do it like this is in case I need to extract more than one value from the query string - the final <code>SELECT</code> can be switched around to produce a table of keys and values. (I would have done so already, but the <code>XzuyEtN2Y1L1QzuyEzzyD0</code> parameter doesn't have a value and I couldn't decide what to do with it).</p> <hr> <p>This is the alternative query (still using <code>@QSXML</code> as above) that gives a tabular result:</p> <pre><code>;With ShreddedNodes as ( select c.value('.','varchar(4000)') as ParmAndValue from @QSXML.nodes('/a/b') t(c) ), Splits as ( select ParmAndValue,CHARINDEX('=',ParmAndValue) as Split from ShreddedNodes ), KeysAndValues as ( select CASE WHEN Split &gt; 0 THEN SUBSTRING(ParmAndValue,1,Split-1) ELSE ParmAndValue END as [Key], CASE WHEN Split &gt; 0 THEN SUBSTRING(ParmAndValue,Split+1,4000) END as Value from Splits ) select * from KeysAndValues </code></pre> <p>Produces:</p> <pre><code>Key Value ---------------------------------- -------------------------------------------------- q hovercrafting+manchester category web a coolmsd f 2 cd 2 XzuyEtN2Y1L1QzuyEzzyD0 NULL cr 1818627175 uref 14 start 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload