Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. CREATE FUNCTION [dbo].[Split]
  2. (@String VARCHAR (max), @Delimiter CHAR (1))
  3. RETURNS
  4. @temptable TABLE (
  5. [items] VARCHAR (max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL)
  6. AS
  7. begin
  8. declare @idx int
  9. declare @slice varchar(max)
  10.  
  11. select @idx = 1
  12. if len(@String)<1 or @String is null return
  13.  
  14. while @idx!= 0
  15. begin
  16. set @idx = charindex(@Delimiter,@String)
  17. if @idx!=0
  18. set @slice = left(@String,@idx - 1)
  19. else
  20. set @slice = @String
  21.  
  22. if(len(@slice)>0)
  23. insert into @temptable(Items) values(@slice)
  24.  
  25. set @String = right(@String,len(@String) - @idx)
  26. if len(@String) = 0 break
  27. end
  28. return
  29. end
  30.  
  31. SELECT [Date Column],Items FROM dbo.Split([Sentence Column],' ')
Add Comment
Please, Sign In to add comment