Update the string at the specified position in the string list.

Source: Internet
Author: User
Code
/* -- Update the string at the specified position in the string list

Update the string list. The string at the specified position is a new value.
If the location is out of the range, no updates are made.

-- Producer build 2004.07 (reference please keep this information )--*/

/*-- Call example

Select DBO. f_updatestr ('001 | 002 | 003 ', 3, '00a',' | ')
-- */
Create   Function F_updatestr (
@ S   Varchar ( 8000 ),
@ POS   Int ,
@ Newstr   Varchar ( 100 ),
@ Spliststr   Varchar ( 10 ) -- Delimiter of the string list
) Returns   Varchar ( 8000 )
As
Begin
  Declare   @ I   Int , @ Ilen   Int
  -- | 001 | 002 | 003 |
  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

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.