Created
March 20, 2018 09:01
-
-
Save LinZap/a25c904e008f8e421e1c092b34d42062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function fn_split(@str nvarchar(max),@separator as nvarchar(max)) | |
returns @splits table(segment nvarchar(max)) | |
as | |
begin | |
declare @anchor int=CHARINDEX(@separator,@str),@gram int=len(@separator) | |
while @anchor>0 and @gram<=len(@str) | |
begin | |
insert into @splits values(SUBSTRING(@str, 1, @anchor-1)) | |
set @str=SUBSTRING(@str,@anchor+@gram,len(@str)-@anchor+@gram+1) | |
set @anchor=CHARINDEX(@separator,@str) | |
end; | |
insert into @splits values(@str) | |
return; | |
end | |
-- by Zap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment