大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 数据库 -> 其他相关 -> 字符串分拆查询

字符串分拆查询

时间: 2021-08-13 作者:daque

有如许的数据  字段1      字段2  2,4,23    3,6,345 23,56,4   3,3,67 取数据的是 查问 字段第11中学 前提是 4 那么在字段2  在取的是6与 67 截止如次 ============ 4     6 4     67 ------------------------------------------------------------------------------- --处置示例 --尝试数据 create table tb(字段1 varchar(10),字段2 varchar(10)) insert tb select ’2,4,23’ ,’3,6,345’ union all select ’23,56,4’,’3,3,67’ go --写个自设置因变量来处置 create function f_value( @a varchar(10), @b varchar(10), @c varchar(10) )returns varchar(10) as begin  declare @i int,@pos int    select @a=left(@a,charindex(’,’+@c+’,’,’,’+@a+’,’)-1)   ,@pos=len(@a)-len(replace(@a,’,’,’’))+1   ,@i=charindex(’,’,@b)  while @i>0 and @pos>1   select @b=substring(@b,@i+1,8000)    ,@i=charindex(’,’,@b)    ,@pos=@pos-1  return(case @pos when 1     then case when @i>0 then left(@b,@i-1) else @b end    else ’’ end) end go --查问 declare @a varchar(10) set @a=’23’ --查问参数 --查问语句 select a=@a,b=dbo.f_value(字段1,字段2,@a) from tb go --简略尝试 drop table tb drop function f_value /*--尝试截止 a            b           ---------- ----------  23         345 23         3 (所感化的行数为 2 行) --*/

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.