Split string by comma in SQL Server 2008

前端 未结 1 1065
你的背包
你的背包 2020-12-06 07:19

There are two strings a and b

The a string contains comma. I would like to split the a string by comma, then go through every

相关标签:
1条回答
  • 2020-12-06 07:49

    Following will work -

    DECLARE @A VARCHAR (100)= '4,5,6'
    DECLARE @B VARCHAR (100)= 'RXXXXXX'
    DECLARE @RETURN_VALUE BIT = 1 --DEFAULT 1
    
    
    SELECT items
    INTO #STRINGS 
    FROM dbo.split(@A,',')
    
    IF EXISTS(SELECT 1 FROM #STRINGS S WHERE CHARINDEX(items, @B) > 0)
    SET @RETURN_VALUE = 0
    
    PRINT @RETURN_VALUE
    
    DROP TABLE #STRINGS
    

    You can also use CONTAINS instead of CHARINDEX -

    IF EXISTS(SELECT 1 FROM #STRINGS S WHERE CONTAINS(items, @B))
    SET @RETURN_VALUE = 0
    
    0 讨论(0)
提交回复
热议问题