Can anyone give me a sample script for batch insert/update of records in table using stored procedure in SQL Server?
I've done something like this in the past:
CREATE PROCEDURE InsertProductIds(@ProductIds xml) AS
INSERT INTO Product (ID)
SELECT ParamValues.ID.value('.', 'VARCHAR(20)')
FROM @ProductIds.nodes('/Products/id') as ParamValues(ID)
END
Obviously this is just a single-column table, but the XML approach applies for multi-column tables as well. You then do this:
EXEC InsertProductIds @ProductIds='<Products><id>3</id><id>6</id></Products>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With