Write a SPLIT function in SQL Server

xiaoxiao2021-03-05  28

Due to the statistics of query, I wrote a function similar to the split in SQLServer this morning, as follows

Create Function F_SPLIT (@SourceSql Varchar (8000), @ straseprate varchar (10)) Returns @temp table (a varchar (100)) - DITER: 2005-4-20 - Date: DominoAs Begin declare @i int set @ SourceSQL = RTRIM (Ltrim (@SourceSQL)) set @ i = charindex (@ straseprate, @ SourceSQL) while @i> = 1 begin insert @temp values ​​(@ SourceSql, @ i-1 ))) SET @ SourceSQL = Substring (@ SourceSQL, @ i 1, len (@Sourcesql) - @ i) set @ i = charindex (@ strseprate, @ SourceSQL) end if @Sourcesql <> '/' insert @temp valuees (@SourcesQL) Return End

Usage: Select * from dbo.f_split ('A: B: C: D: E', ':')

转载请注明原文地址:https://www.9cbs.com/read-34060.html

New Post(0)