设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> 数据库开发 >> Ntext字段拆分处理
精品推荐
数据库开发点击TOP10
·MYSQL 新版出现 Client does not support authentication protocol requested by server; consider upgrading MySQL client解决办法
·生成助记码(取汉字的第一个字母)
·ORA-01034错误的解决办法
·ORACLE数据库管理员的职责
·将DW数据窗口导出为EXCEL文件的方法(整理)
·Oracle中分区表的使用
·SQL Server 2000+ MS WIN2003群集服务配置
·SQL中UNION 与 UNION ALL 的区别
·ORA-00257: archiver error. Connect internal only, until freed.
·Oracle备份与恢复案例
编程开发点击TOP10
·数字小键盘指法练习
·ASP.NET 程序中常用的三十三种代码
·用C语言编通讯录程序(初学者级别的)
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

Ntext字段拆分处理

作者: 来源:网络文章 时间:2005-12-17 22:32:18

Ntext字段拆分处理(1)

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型字段为主键
 如果不满足这个条件,则要对应的修改存储过程

--邹建 2004.07--*/

/*--调用示例

 --测试数据
 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)

 
 --调用存储过程,进行拆分
 exec p_split 'tb','content',',','id=3'

 drop table tb
--*/

create proc p_split
@tbname sysname,  --要处理的表名
@fdname sysname,  --text/ntext字段名
@splitchar nvarchar(10)=',',--拆分的字符串分隔符
@where nvarchar(1000)=''--要处理的记录的条件
as
if 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 int
declare @sp1 varchar(10),@step int

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

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

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

共2页 9 7 [1] [28 :>

Ntext字段拆分处理 相关文章:
Ntext字段拆分处理 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com