select @prono as prono ,@cityname as cityname,@countryname as countryname,@proname as proname,@villagename as villagename,@dissituation as dissituation,@measures as measures,@peoplenum as peoplenum,@directloss as directloss,@pronum as pronum ,@restorefund as restorefund,@id as id,@F1 as F1 into abcd from OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;HDR=No;IMEX=1;DATABASE='+@filename+''',[西安市$])' --以上你的@prono定義後沒有賦值,所以全是NULL --還有你邏輯有點混亂,你目的是從Excel中查詢插入到表abcd,而你select 後面全是變量,等於沒有from openrowset --還有你沒必要用過度表abcd,直接操作execl
不要测试,看看结果是什么 declare @t table(id int) insert @t select 1 union all select 2 create table #(id int) declare @id int insert # select @id from @t select @id select * from @t drop table #
declare @t table(id int) insert @t select 1 union all select 2declare @id int select @id id into # from @tselect * from # /* NULL NULL */drop table #
--以上你的@prono定義後沒有賦值,所以全是NULL
--還有你邏輯有點混亂,你目的是從Excel中查詢插入到表abcd,而你select 後面全是變量,等於沒有from openrowset
--還有你沒必要用過度表abcd,直接操作execl
declare @t table(id int)
insert @t select 1 union all select 2
create table #(id int)
declare @id int
insert # select @id from @t
select @id
select * from @t
drop table #
insert @t select 1 union all select 2declare @id int
select @id id into # from @tselect * from #
/*
NULL
NULL
*/drop table #
insert OPENDATASOURCE(
'SQLOLEDB',
'Data Source=远程ip;User ID=sa;Password=密码'
).库名.dbo.表名 (列名1,列名2)
SELECT 列名1,列名2
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions