Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [lime_crm_base_solution_v7_0_1]
- GO
- /****** Object: UserDefinedFunction [dbo].[cfn_lc_gettablefromstring] Script Date: 2019-09-19 14:04:30 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- Written by: Fredrik Eriksson
- -- Created: 2015-11-05
- -- ##########
- -- DISCLAIMER:
- -- This procedure is a built in procedure in Lime Core.
- -- Modifying it could have consequences beyond your imagination.
- -- Or not.
- -- Seriously though, you should always make sure that no other built in functionality breaks if you must modify this procedure.
- -- ##########
- -- Splits a string separated by a delimiter into a table.
- ALTER FUNCTION [dbo].[cfn_lc_gettablefromstring]
- (
- @@string NVARCHAR(MAX)
- , @@delimiter NVARCHAR(1)
- )
- RETURNS @result TABLE
- (
- [value] NVARCHAR(128)
- )
- AS
- BEGIN
- -- Check parameters
- IF ISNULL(@@delimiter, N'') = N''
- OR ISNULL(@@string, N'') = N''
- BEGIN
- RETURN
- END
- -- Add delimiter at the end of the string
- IF SUBSTRING(@@string, LEN(@@string), 1) <> @@delimiter
- BEGIN
- SET @@string += @@delimiter
- END
- -- Go through the string
- DECLARE @lastpos INT
- SET @lastpos = 0
- WHILE @lastpos < LEN(@@string)
- BEGIN
- INSERT INTO @result(value)
- VALUES (SUBSTRING(@@string, @lastpos, CHARINDEX(@@delimiter,@@string, @lastpos) - @lastpos))
- SET @lastpos = CHARINDEX(@@delimiter,@@string, @lastpos) + 1
- END
- RETURN
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement