CREATE PROCEDURE [dbo].[BulkInsert] ( @PID int , @x int, @y int,) AS BEGIN SET NOCOUNT ON;declare @query varchar(max)CREATE TABLE #TEMP ( [PID] [int] NOT NULL , [x] int NOT NULL, [y] int NOT NULL,)SET @query = 'BULK INSERT #TEMP FROM ''' + PathOfYourTextFile + ''' WITH ( FIELDTERMINATOR = '','',ROWTERMINATOR = ''n'')' --print @query --return execute(@query)BEGIN TRAN;MERGE TableName AS Target USING (SELECt * FROM #TEMP) AS Source ON (Target.YourTableId = Source.YourTextFileFieldId)-- In the above line we are checking if the particular row exists in the table(Table1) then update the Table1 if not then insert the new row in Table-1.WHEN MATCHED THEN UPDATE SET Target.PID= Source.PID, Target.x= Source.x, Target.y= Source.yWHEN NOT MATCHED BY TARGET THEN-- Insert statement
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)