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

Insira várias linhas na tabela temporária com um comando no SQL2005


Tente algo como
CREATE TABLE #TEMP 
( 
    Node int 
) 


DECLARE @textXML XML
DECLARE @data NVARCHAR(MAX), 
        @delimiter NVARCHAR(5)
SELECT  @data = '-1,-1,-1,-1,701,-1,-1,-1,-1,-1,304,390,403,435,438,439,442,455 ',
        @delimiter = ','
SELECT    @textXML = CAST('<d>' + REPLACE(@data, @delimiter, '</d><d>') + '</d>' AS XML)

INSERT INTO #TEMP
SELECT  T.split.value('.', 'nvarchar(max)') AS data
FROM    @textXML.nodes('/d') T(split)

SELECT * FROM #TEMP

DROP TABLE #TEMP