Excel文件中品號寫入單價
阿新 • • 發佈:2018-06-21
temp HERE top excel文件 文件中 subst while sof PE
declare @XUHAO int,
@TM004 varchar(20),
@TD010 numeric(16,2),
@i int = 1 ,@x int
IF OBJECT_ID(‘tempdb..#TempA‘) IS NOT NULL DROP TABLE #TempA
select ROW_NUMBER() OVER (ORDER BY @XUHAO ASC) AS ID, * into #TempA from
OPENROWSET
(
‘Microsoft.Ace.OleDb.12.0‘
,‘Excel 12.0;DATABASE=C:\Users\Administrator\Desktop\產品\301.xls‘
,‘SELECT * FROM [Sheet1$]‘
)
select @x = COUNT(*) from #TempA
print @x
while @i <= @x
begin
select @TM004 = 元件品號 from #TempA where ID = @i
if @TM004 is not null
begin
select TOP 1 @TD010 = TD010 from TOPLED2015..PURTD where TD018 = ‘Y‘ and TD004 = @TM004 ORDER BY substring(TD002,1,8) DESC
if @TD010 <> 0
begin
update
OPENROWSET
(
‘Microsoft.Ace.OleDb.12.0‘
,‘Excel 12.0;DATABASE=C:\Users\Administrator\Desktop\產品\301.xls‘
,‘SELECT * FROM [Sheet1$]‘
)
set 投料間距 = @TD010
where 元件品號 = @TM004
end
end
set @i = @i + 1
end
IF OBJECT_ID(‘tempdb..#TempA‘) IS NOT NULL DROP TABLE #TempA
Excel文件中品號寫入單價