Copy codeThe Code is as follows:
DECLARE @ c INT
DECLARE @ c2 INT
SELECT @ c = COUNT (1)
FROM dbo. SplitToTable ('1 | 2 | 3 | 4', '| ')
SELECT @ c2 = COUNT (1)
FROM dbo. SplitToTable ('1 | 2 | 3 | 4', '|')
Inner join dbo. SplitToTable ('1 | 2 | 3 | ',' | ') B ON a. value = B. value
IF @ c = @ c2
SELECT 'OK'
ELSE
SELECT 'no'
The SplitToTable function is as follows:
Set ANSI_NULLS ON
Set QUOTED_IDENTIFIER ON
Go
Alter function [dbo]. [SplitToTable]
(
@ SplitString NVARCHAR (MAX ),
@ Separator NVARCHAR (10) =''
)
RETURNS @ SplitStringsTable TABLE
(
[Id] int identity (1, 1 ),
[Value] NVARCHAR (MAX)
)
AS
BEGIN
DECLARE @ CurrentIndex INT;
DECLARE @ NextIndex INT;
DECLARE @ ReturnText NVARCHAR (MAX );
SELECT @ CurrentIndex = 1;
WHILE (@ CurrentIndex <= LEN (@ SplitString ))
BEGIN
SELECT @ NextIndex = CHARINDEX (@ Separator, @ SplitString,
@ CurrentIndex );
IF (@ NextIndex = 0
OR @ NextIndex IS NULL
)
SELECT @ NextIndex = LEN (@ SplitString) + 1;
SELECT @ ReturnText = SUBSTRING (@ SplitString,
@ CurrentIndex,
@ NextIndex-@ CurrentIndex );
Insert into @ SplitStringsTable
([Value])
VALUES (@ ReturnText );
SELECT @ CurrentIndex = @ NextIndex + 1;
END
RETURN;
END