Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Fractionner la chaîne via l'instruction 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