sqlserver 直接查询excel

select identity(int, 1, 1) rownum,*
  into #temp
  from OpenRowSet(
'Microsoft.Jet.OLEDB.4.0',
                 
'Excel 8.0;IMEX=1;Database=D:\work_数创\客户\网球\设计\餐娱物资清单\杯子.xls',
                 
'select  * from [Sheet1$] ');

select F2, f3, f4, f5 from #temp where rownum >
1;
drop table #temp

 

 

1.   物资清单_不锈钢物品录入

drop table #temp

select identity(int, 1, 1) rownum,*

  into #temp

  from OpenRowSet('Microsoft.Jet.OLEDB.4.0',

                  'Excel 8.0;IMEX=1;HDR=NO;Database=D:\work_数创\客户\网球\设计\餐娱物资清单\厨房所有不锈钢杂件、表格.xls',

                  'select  * from [总表$] ');

 

 

 

INSERT INTO [sciitc_dw].[dbo].[d_餐娱物资_厨房不锈钢_维表]

           ([序号]

           ,[名称]

           ,[规格]

           ,[单位]

           ,[原数量]

           ,[盘点数量]

           ,[备注]

           ,[录入时间])

select F1,F2,F3,F4,F5,F6,F7,GETDATE() from #temp where rownum > 2

and F1  is not null;

小吃房

drop table #temp

select identity(int, 1, 1) rownum,*

  into #temp

  from OpenRowSet('Microsoft.Jet.OLEDB.4.0',

                  'Excel 8.0;IMEX=1;HDR=NO;Database=D:\work_数创\客户\网球\设计\餐娱物资清单\厨房所有不锈钢杂件、表格.xls',

                  'select  * from [小吃房$] ');

 

select *,GETDATE() from #temp where rownum > 1

INSERT INTO [sciitc_dw].[dbo].[s_餐娱物资盘点_厨房不锈钢_各部门]

           ([序号]

           ,[名称]

           ,[单位]

           ,[数量]

           ,[备注]

           ,[规格]

           ,[使用时间]

           ,[使用部门id])

         

select a.[序号],b.F2,b.F3,b.F4,b.F5,a.[规格],GETDATE(), 

(select 使用部门id from dbo.d_餐娱物资_厨房不锈钢_使用部门 where 使用部门名称='小吃房')

from #temp b,  [dbo].[d_餐娱物资_厨房不锈钢_维表] a

where b.F2 = a.[名称]

 

 

 

 

散客录入

drop table #temp

select identity(int, 1, 1) rownum,*

  into #temp

  from OpenRowSet('Microsoft.Jet.OLEDB.4.0',

                  'Excel 8.0;IMEX=1;HDR=NO;Database=D:\work_数创\客户\网球\前期需求调研_20110722\报表\前厅所需报表\2011年月份自来散客统计.xls',

                  'select  * from [sheet1$] ');

 

select *,GETDATE() from #temp where rownum > 1

 

INSERT INTO [sciitc_dw].[dbo].[d_Global_Customer]

           ([客户id]

           ,[客户名称]

           ,[客源类型id]

           ,[客源类型名称],实际入住时间,实际离店时间,房号,金额)

         

select F1, b.F3, 6,'散客' ,b.F5  , b.F6 , b.F4, b.F7

 

from #temp b where rownum > 2 and F1 is not null

 

posted @ 2011-08-02 23:37  木子非  阅读(637)  评论(1编辑  收藏  举报