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

 All Forums
 General SQL Server Forums
 Script Library
 FUNCTION: ParseBrowser

Author  Topic 

aiken
Aged Yak Warrior

525 Posts

Posted - 2002-03-23 : 15:03:01
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
BEGIN
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

END


Cheers
-b

   

- Advertisement -