我有这个代码
USE [DATABASE]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetDataExcel]
as
DECLARE c CURSOR FOR select Box, Code , Validity FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Barcodes.xlsx;HDR=YES', 'SELECT Box, Code , Validity FROM [sheet1$]')
declare @Code as bigint
declare @Box as bigint
declare @Validity as date
begin
open c
fetch next from c into @Box,@Code,@Validity
WHILE @@FETCH_STATUS = 0
begin
Insert into Cards (Box, BarCode, ValidityDate) select Box, Code , Validity FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Barcodes.xlsx;HDR=YES', 'SELECT Box, Code , Validity FROM [sheet1$]')
fetch next from c into @Box,@Code,@Validity
end
CLOSE c
DEALLOCATE c
end
在导出到表“卡片”时,空行也被复制到表中并且进程不会停止,循环继续进行并且进程一遍又一遍地重新启动,查询不会停止执行,除非我停止它,当我看到表格的内容时,我看到空行的 NULL 值和填充行的值,并且它们是重复的,那么如何阻止查询读取空行并阻止它读取 excel 文件和结束?