Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 FUNCTION: ParseBrowser
 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  
 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.02 seconds. Powered By: Snitz Forums 2000