Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. USE [lime_crm_base_solution_v7_0_1]
  2. GO
  3. /****** Object: UserDefinedFunction [dbo].[cfn_lc_gettablefromstring] Script Date: 2019-09-19 14:04:30 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. -- Written by: Fredrik Eriksson
  10. -- Created: 2015-11-05
  11.  
  12. -- ##########
  13. -- DISCLAIMER:
  14. -- This procedure is a built in procedure in Lime Core.
  15. -- Modifying it could have consequences beyond your imagination.
  16. -- Or not.
  17. -- Seriously though, you should always make sure that no other built in functionality breaks if you must modify this procedure.
  18. -- ##########
  19.  
  20. -- Splits a string separated by a delimiter into a table.
  21.  
  22. ALTER FUNCTION [dbo].[cfn_lc_gettablefromstring]
  23. (
  24. @@string NVARCHAR(MAX)
  25. , @@delimiter NVARCHAR(1)
  26. )
  27. RETURNS @result TABLE
  28. (
  29. [value] NVARCHAR(128)
  30. )
  31. AS
  32. BEGIN
  33. -- Check parameters
  34. IF ISNULL(@@delimiter, N'') = N''
  35. OR ISNULL(@@string, N'') = N''
  36. BEGIN
  37. RETURN
  38. END
  39.  
  40. -- Add delimiter at the end of the string
  41. IF SUBSTRING(@@string, LEN(@@string), 1) <> @@delimiter
  42. BEGIN
  43. SET @@string += @@delimiter
  44. END
  45.  
  46. -- Go through the string
  47. DECLARE @lastpos INT
  48. SET @lastpos = 0
  49.  
  50. WHILE @lastpos < LEN(@@string)
  51. BEGIN
  52. INSERT INTO @result(value)
  53. VALUES (SUBSTRING(@@string, @lastpos, CHARINDEX(@@delimiter,@@string, @lastpos) - @lastpos))
  54.  
  55. SET @lastpos = CHARINDEX(@@delimiter,@@string, @lastpos) + 1
  56. END
  57.  
  58. RETURN
  59. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement