Parsing a Querystring using TSQL.

jesus4u

Well-known member
Joined
Feb 13, 2003
Messages
47
I need each param parsed out of this string. I am having trouble parsing if the vars vary in length.

Data: ec=TTT&oc=CRM&tot=501&UID=88997

Code:
(SELECT
	   ID, IP, TID, TheUserDetails.UserID as UserID, 
	   --Parsing
	   Querystring,
	   SUBSTRING(Querystring, CHARINDEX(ec=,Querystring) + 3, CHARINDEX(&, Querystring) - 4) as EC,
	   SUBSTRING(Querystring, CHARINDEX(oc=,Querystring) + 3, CHARINDEX(&, Querystring) - 4) as OC,
	   SUBSTRING(Querystring, CHARINDEX(tot=,Querystring) + 4, CHARINDEX(&, Querystring) - 5) as TOT,
	   SUBSTRING(Querystring, CHARINDEX(uid=,Querystring) + 4, 50) as UID
	  FROM WebLog l LEFT JOIN
                     dbo.TheUserDetails ON 
		     l.TID = TheUserDetails.TrackID)




Edited by - jesus4u on 03/11/2003 12:53:33
 
Back
Top