DECLARE @btnID nVarChar(15)=’10_2′;
DECLARE @QID INT, @AID INT;
SET @QID = CAST(LEFT(@btnID, CHARINDEX(‘_’, @btnID) – 1) AS INT);
SET @AID = CAST(RIGHT(@btnID, LEN(@btnID) – CHARINDEX(‘_’, @btnID)) AS INT);
—————————————————————————–
DECLARE @strThis nVarChar(100) = ‘a,b,c,d’;
DECLARE @splitValues TABLE (Value nVarChar(100))
IF (SELECT COUNT(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[STRING_SPLIT]’)) > 0
BEGIN
INSERT INTO @splitValues
SELECT value FROM STRING_SPLIT(@strThis, ‘,’)
END
ELSE
BEGIN
DECLARE @pos INT = CHARINDEX(‘,’, @strThis)
DECLARE @val nVarChar(100)
WHILE @pos > 0
BEGIN
SET @val = LEFT(@strThis, @pos – 1)
INSERT INTO @splitValues
VALUES (@val)
SET @strThis = RIGHT(@strThis, LEN(@strThis) – @pos)
SET @pos = CHARINDEX(‘,’, @strThis)
END
INSERT INTO @splitValues
VALUES (@strThis)
END
SELECT * FROM @splitValues