0
我有以下代碼將Excel數據導入到表中並更新了一些參數,但是我無法讀取所有行,只有最後一行正在讀取,我希望能夠讀取所有的行,並更新其值在表在導入時讀入Excel中的最後一行 - SQL數據庫
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
[email protected] ,
[email protected],
Activated=1,
[email protected],
[email protected],
ImportDate=GETDATE(),
CollectionDeadlineDate=DateAdd(Day,30,ImportDate)
where [email protected]
fetch next from c into @Barcode,@MSISDN,@POS,@SIMCardNb,@ActivatedDate
end
CLOSE c
DEALLOCATE c