关于sql server批量插入和更新的两种解决方案
网络整理 - 08-21
.游标方式 1 DECLARE @Data NVARCHAR(max)
SET @Data='1,tanw;2,keenboy' --Id,Name
DECLARE @dataItem NVARCHAR(100)
DECLARE data_cursor CURSOR FOR (SELECT * FROM split(@Data,';'))
OPEN data_cursor
FETCH NEXT FROM data_cursor INTO @dataItem
WHILE @@FETCH_STATUS=0
BEGIN
DECLARE @Id INT
DECLARE @Name NVARCHAR(50)
DECLARE dataItem_cursor CURSOR FOR (SELECT * FROM split(@dataItem,','))
OPEN dataItem_cursor
FETCH NEXT FROM dataItem_cursor INTO @Id
FETCH NEXT FROM dataItem_cursor INTO @Name
CLOSE dataItem_cursor
DEALLOCATE dataItem_cursor
/*
在这里做逻辑处理,插入或更新操作 ...
*/
END
CLOSE data_cursor
DEALLOCATE data_cursor