CREATE TABLE #t(i INT IDENTITY(1,1),c varchar(max)); INS...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

CREATE TABLE #t(i INT IDENTITY(1,1),c varchar(max));

INSERT INTO #t(c)
SELECT 'Hello,World'
UNION ALL SELECT  'Code,Golf,Is,Cool'
UNION ALL SELECT  '1,2,3,4,5'
UNION ALL SELECT  'This,test,case,is,true'         
UNION ALL SELECT  '111,010,000,1101,1010,1000,0111,0010,1011,0110,11001,00110,10011,11000,00111,10010'
UNION ALL SELECT  '4,42'
UNION ALL SELECT  '1,2,3,34'                   
UNION ALL SELECT  'This,test,case,is,false,t'
UNION ALL SELECT  'He,said,Hello'
UNION ALL SELECT  '0,00,00001'
UNION ALL SELECT  'Duplicate,Duplicate,Keys,Keys';

WITH y AS (SELECT *,z=value,r=ROW_NUMBER()OVER(ORDER BY 1/0) FROM #t CROSS APPLY STRING_SPLIT(c,','))
SELECT y.c, IIF(COUNT(u.z)>0,'F','T')
FROM y LEFT JOIN y u ON y.i=u.i AND y.r<>u.r AND y.z LIKE u.z+'%' 
GROUP BY y.c

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results