更新字符串列表中,指定位置的字符串

王朝mssql·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

更新字符串列表中,指定位置的字符串

更新字符串列表中,指定位置的字符串 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_updatestr]') and xtype in (N'FN', N'IF', N'TF'))

drop function [dbo].[f_updatestr]

GO

/*--更新字符串列表中,指定位置的字符串

更新字符串列表中,指定位置的字符串为新的值

如果位置超出范围,则不做更新

--邹建 2004.07--*/

/*--调用示例

select dbo.f_updatestr('001|002|003|',1,'00a','|')

--*/

create function f_updatestr(

@s varchar(8000),

@pos int,

@newstr varchar(100),

@spliststr varchar(10) --字符串列表的分隔符

)returns varchar(8000)

as

begin

declare @i int,@ilen int

select @i=charindex(@spliststr,@spliststr+@s)

,@ilen=len(@spliststr)

while @i>0 and @pos>1

select @i=charindex(@spliststr,@s,@i)+@ilen

,@pos=@pos-1

return(case @i when 0 then @s else stuff(@s,@i,charindex(@spliststr,@s+@spliststr,@i)-@i,@newstr) end)

end

go

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航