我有以下代码将 Excel 数据导入表并更新一些参数,但是我无法读取所有行,只读取最后一行,我希望能够读取所有行并更新它们的值桌子
DECLARE c CURSOR FOR select Barcode,MSISDN,POS,[SIM Card Number],[Date of Sale] FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\ActivatedCards.xlsx;HDR=YES', 'SELECT Barcode,MSISDN,POS,[SIM Card Number],[Date of Sale] FROM [sheet1$]')
declare @Barcode as bigint
declare @MSISDN as bigint
declare @POS as nvarchar(50)
declare @SIMCardNb as bigint
declare @ActivatedDate as date
begin
open c
fetch next from c into @Barcode,@MSISDN,@POS,@SIMCardNb,@ActivatedDate
WHILE @@FETCH_STATUS = 0
begin
select @Barcode=Barcode,@MSISDN=MSISDN,@POS=POS,@SIMCardNb=[SIM Card Number],@ActivatedDate=[Date of Sale] FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\ActivatedCards.xlsx;HDR=YES', 'SELECT Barcode,MSISDN,POS,[SIM Card Number],[Date of Sale] FROM [sheet1$]')
where Barcode <> ''
Update Cards
set
MSISDN=@MSISDN ,
POSSold=@POS,
Activated=1,
SIMCardNb=@SIMCardNb,
ActivatedDate=@ActivatedDate,
ImportDate=GETDATE(),
CollectionDeadlineDate=DateAdd(Day,30,ImportDate)
where Cards.BarCode=@Barcode
fetch next from c into @Barcode,@MSISDN,@POS,@SIMCardNb,@ActivatedDate
end
CLOSE c
DEALLOCATE c