SQl:从文本文件更新表

SQl:从文本文件更新表,第1张

SQl:从文本文件更新
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

您可以使用上面的方法来解决您的问题。希望这可以帮助。:)



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5618337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存