Created
September 20, 2011 17:42
-
-
Save mbmccormick/1229762 to your computer and use it in GitHub Desktop.
Bulk INSERT LINQ collection via XML serialization and stored procedures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET ANSI_NULL ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE PROCEDURE dbo.InsertStopTimes | |
@SerializedData xml, | |
@NewPartitionKey uniqueidentifier, | |
@OldPartitionKey uniqueidentifier | |
AS | |
INSERT INTO StopTimes(RowKey, PartitionKey, StopID, TripID, ArrivalTime, DepartureTime, StopSequence) | |
SELECT T.c.value('./RowKey[1]', 'uniqueidentifier'), | |
T.c.value('./PartitionKey[1]', 'uniqueidentifier'), | |
T.c.value('./StopID[1]', 'varchar(50)'), | |
T.c.value('./TripID[1]', 'varchar(50)'), | |
T.c.value('./ArrivalTime[1]', 'datetime'), | |
T.c.value('./DepartureTime[1]', 'datetime'), | |
T.c.value('./StopSequence[1]', 'int') | |
FROM @SerializedData.nodes('/ArrayOfStopTime/StopTime') T(c) | |
UPDATE Agency SET PartitionKey = @NewPartitionKey WHERE PartitionKey = @OldPartitionKey | |
DELETE FROM StopTimes WHERE PartitionKey = @OldPartitionKey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment