Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Separe a string por meio da instrução select

DECLARE @LeftPart TABLE
(Agent int
)

DECLARE @RightPart TABLE
(Agent1 int
)

declare @Agent nvarchar(4000) = '2131235,334225';

INSERT INTO @LeftPart
SELECT LEFT(@Agent,7)

INSERT INTO @RightPart
SELECT RIGHT(@Agent,6)

SELECT * INTO #Temp
FROM 
(
SELECT * FROM @LeftPart
UNION ALL
SELECT * FROM @RightPart
)A

SELECT * FROM #Temp