SQLServer Custom Function - FNSPLIT

xiaoxiao2021-03-05  23

/ ************************************************** ************** File: fnsplit.sql ** name: fnsplit ** description: split the string. Split string ** Return Values: @temp ** parameters: @ SQL, @ Splits ** Author: Godness ** Date: 2005-1-11 ** Use method: select * from dbo.split ('1, 2, 3, 4', ',') ****** *********************************************************** ***** /

Create Function Split (@SQL VARCHAR (8000), @SPLITS VARCHAR (100)) Returns @temp table (TempColumn varchar (100)) asbegin declare @i int set @sql = rtrim (Ltrim (@SQL)) set @i = Charindex (@ splits, @ SQL) while @i> = 1 begin insert @temp valuees (left (@ SQL, @ i-1)) set @SQL = Substring (@ SQL, @ i len (@Splits), Len (@SQL) - @ i) set @i = charIndex (@ splits, @ SQL) end

IF @SQL <> '' INSERT @Temp Values ​​(@SQL) Returnend

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

New Post(0)