利用sqlserver 的sql语句如何从下面的列中抽取出我想要的结果呢
列的内容:
reurl=index.aspx&visitedforums=2;+User_Cookie=UserName=admin&UserPwd=[color=#00FF00]admin;+ASP.NET_SessionId=jph5hebcqk3piitv3vkxj1xg[/color]
我现在就想要用户名 admin
我的表名叫 test1 字段名是 zhang
select () from test1
结果 :test
()中应该填写什么呢???
------解决方案--------------------
- SQL code
declare @s varchar(max)set @s='reurl=index.aspx&visitedforums=2;+User_Cookie=UserName=admin&UserPwd=admin;+ASP.NET_SessionId=jph5hebcqk3piitv3vkxj1xg'select right(PARSENAME(replace(replace(@s,'.','@'),';','.'),2),CHARINDEX(@s,'=')-1)
------解决方案--------------------
- SQL code
if object_id('[test1]') is not null drop table [test1]gocreate table [test1]([id] int,[zhang] varchar(92))insert [test1]select 1,'eurl=index.aspx&visitedforums=2;+User_Cookie=UserName=admin&UserPwd=admin;+ASP.NET_SessionId'goselect username=left(stuff(zhang,1,charindex('UserName=',zhang)+8,''),charindex('&',stuff(zhang,1,charindex('UserName=',zhang)+8,''))-1)from test1/**username-----------------------------------admin(1 行受影响)**/