In the update string list, the string at the specified position

Source: Internet
Author: User
String
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

/*--the string for the specified position in the list of update strings

Update string list, the string at the specified position is a new value if the position is out of range, do not update

--Jiangjian 2004.07--*/

/*--Call Example

Select Dbo.f_updatestr (' 001|002|003| ', 1, ' 00a ', ' | ') --*/create function F_updatestr (@s varchar (8000), @pos int, @newstr varchar (MB), @spliststr varchar (10)--delimiter for List of strings) Returns varchar (8000) Asbegin 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 Endgo




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.