SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 FUNCTION: ParseBrowser
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

525 Posts

Posted - 03/23/2002 :  15:03:01  Show Profile  Send aiken an ICQ Message  Reply with Quote
Here's a handy little function that will parse normal HTTP USER_AGENT strings and return either Mozilla/X.XX or MSIE X.XX (it also seems to get Opera and Konqueror properly). It's handy if you stuff this info into a database; for instance,

select dbo.f_ParseBrowser(last_browser),count(*) from users group by dbo.f_ParseBrowser(last_browser) order by count(*) desc

Here's the function:

CREATE FUNCTION dbo.f_ParseBrowser (@vcBrowser varchar(200))
RETURNS varchar(50) AS
DECLARE @vcMoz varchar(15),@vcData varchar(200)
DECLARE @iPos int

select @iPos=charindex(' ',@vcBrowser)
if @iPos=0
return '(unkown): ' + @vcBrowser

select @vcMoz=substring(@vcBrowser,1,@iPos-1)
select @vcData=substring(@vcBrowser,@iPos+1,200)

select @iPos=patindex('%compatible; %',@vcData)
if @iPos=0
return @vcMoz

select @vcData=substring(@vcData,@iPos+12,len(@vcData)-12)
select @iPos=CharIndex(';',@vcData)
if @iPos=0
return @vcData

select @vcData=substring(@vcData,1,@iPos-1)

return @vcData



  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000