Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Inserire più righe utilizzando la procedura memorizzata e il parametro XML?

Puoi distruggere l'XML usando la funzione nodes:

CREATE PROC ShredXML (@x xml)
AS BEGIN
    INSERT INTO TBL_TARGET (Name, Color)
    SELECT 
        x.y.value( 'Name[1]', 'VARCHAR(20)' ) AS Name,
        x.y.value( 'Color[1]', 'VARCHAR(20)' ) AS Color
    FROM @x.nodes('cars/car') x(y)
END


exec ShredXML @x = N'<cars><car><Name>BMW</Name><Color>Red</Color></car><car><Name>Audi</Name><Color>Green</Color></car></cars>'