国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

Ntext字段拆分處理

2024-07-21 02:07:47
字體:
供稿:網(wǎng)友


收集最實(shí)用的網(wǎng)頁特效代碼!


if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[p_split]') and objectproperty(id, n'isprocedure') = 1)drop procedure [dbo].[p_split]go

/*--ntext字段拆分處理

 按指定的分隔符,將 ntext 字段拆分成多條記錄 注意:處理過程固定以名為id的int型字段為主鍵 如果不滿足這個(gè)條件,則要對(duì)應(yīng)的修改存儲(chǔ)過程

--鄒建 2004.07--*/

/*--調(diào)用示例

 --測(cè)試數(shù)據(jù) create table tb(id int identity(1,1),content ntext) insert tb select '001,002' union all select '001,002,003,004,005,006,007,008,009,010' union all select replicate('001,002,003,004,005,006,007,008,009,010',8000)

  --調(diào)用存儲(chǔ)過程,進(jìn)行拆分 exec p_split 'tb','content',',','id=3'

 drop table tb--*/

create proc [email protected] sysname,  --要處理的表名@fdname sysname,  --text/ntext字段名@splitchar nvarchar(10)=',',--拆分的字符串分隔符@where nvarchar(1000)=''--要處理的記錄的條件asif isnull(@splitchar,'')='' set @splitchar=','

declare @s nvarchar(4000)set @s='create table #t(id int identity(1,1),re nvarchar(50))declare @id int,@ptr varbinary(16)declare @s nvarchar(4000),@i int,@j intdeclare @sp1 varchar(10),@step int

select @sp1=reverse(@splitchar),@step=len(@splitchar)

declare tb cursor local for select id,s=substring(['[email protected]+'],1,4000)from ['[email protected]+']where datalength(['[email protected]+'])>0 '+case isnull(@where,'') when '' then ''  else ' and('[email protected]+')' end+'

open tb fetch tb into @id,@swhile @@fetch_status=0begin set @i=1 while @s<>'''' begin  if len(@s)=4000   select @j=4000-charindex(@sp1,reverse(@s))    ,@[email protected][email protected][email protected]    ,@s=left(@s,@j)  else    select @[email protected]+4000,@j=len(@s)  insert #t select substring(@s,id,charindex(@splitchar,@[email protected],id)-id)  from 序數(shù)表  where id<[email protected][email protected] and charindex(@splitchar,@[email protected],id)-id=0  select @s=substring(['[email protected]+'],@i,4000)  from ['[email protected]+']  where [email protected] end

 fetch tb into @id,@sendclose tbdeallocate tbselect * from #t'exec sp_executesql @s ,n'@splitchar nvarchar(10)' ,@splitchargo

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长垣县| 平度市| 汉阴县| 三原县| 游戏| 蓬莱市| 肃宁县| 咸丰县| 册亨县| 陕西省| 万源市| 凤庆县| 中宁县| 温泉县| 龙里县| 建湖县| 巴东县| 高唐县| 伊金霍洛旗| 曲靖市| 莱西市| 祥云县| 万安县| 苗栗市| 安达市| 若尔盖县| 通化市| 马尔康县| 左权县| 永定县| 应城市| 仁怀市| 温泉县| 永福县| 筠连县| 米林县| 台东市| 平舆县| 昌宁县| 齐齐哈尔市| 广德县|