网络上很多ACCESS数据导出的例子,可一直没有找到一份好的比较全的例子,现在我帖一份出来我们正在用的方案共享给大家,有需要的朋友可以改下参数DEMO一下:
/********************服务器导出Access********************/
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--执行参数
declare @filename varchar(20) --Access文件名表径
declare @AccessUser varchar(20)--Access访问用户
declare @AccessPassword varchar(20)--Access访问密码
declare @DataBaseName varchar(40)--服务器数据库名
declare @Yearno varchar(20)--查询年份
declare @SeasonCode varchar(20)--查询季度
declare @SourceBilltype varchar(20)--查询定单类型
set @filename='C:\dts\DB\order.mdb'
set @AccessUser='admin'
set @AccessPassword=''
set @DataBaseName='[yc]'
set @Yearno='2005'
set @SeasonCode='N006'
set @SourceBilltype='weborder'
--Sal_OrderMaster表导出
print 'Sal_OrderMaster表导出'
exec('insert into openrowset(''Microsoft.Jet.OLEDB.4.0'','''+@filename+''';'''+@AccessUser+''';'''+@AccessPassword+''',
''SELECT [CompanyCode], [BillNo], [StockCode], [VendCustCode], [BillType], [OrderType],
[BillDate], [ManualBillNo], [SourceBillNo], [SourceBillType], [AccountCode],
[DepartmentCode], [CurrencyCode], [ExchangeRate], [PayAmount], [Deposit],
[PayMethod], [TransportMethod], [BalaMethod], [EmployeeCode], [Decimal], [BillStatus],
[Operator], [Checker], [Finished], [CheckDate], [Remark], [CardCode], [KindCode],
[YearNo], [SeasonCode], [IsLock], [Qty], [BalaAmount]
FROM [Sal_OrderMaster]''
)SELECT [CompanyCode], [BillNo], [StockCode], [VendCustCode], [BillType], [OrderType],
[BillDate], [ManualBillNo], [SourceBillNo], [SourceBillType], [AccountCode],
[DepartmentCode], [CurrencyCode], [ExchangeRate], [PayAmount], [Deposit],
[PayMethod], [TransportMethod], [BalaMethod], [EmployeeCode], [Decimal], [BillStatus],
[Operator], [Checker], [Finished], [CheckDate], [Remark], [CardCode], [KindCode],
[YearNo], [SeasonCode], [IsLock], [Qty], [BalaAmount]
FROM '+@DataBaseName+'.[dbo].[Sal_OrderMaster]
WHERE Yearno='''+@Yearno+''' and SeasonCode='''+@SeasonCode+''' and SourceBilltype='''+@SourceBilltype+'''
')
--Sal_OrderDetail表导出
print 'Sal_OrderDetail表导出'
exec('insert into openrowset(''Microsoft.Jet.OLEDB.4.0'','''+@filename+''';'''+@AccessUser+''';'''+@AccessPassword+''',
''SELECT [CompanyCode], [BillNo], [Sequence], [SourceBillSequence], [MaterialCode],
[BatchNo], [BoxCode], [BoxQty], [Price], [CostPrice], [Qty], [StockQty],
[StockAmount], [RejectQty], [RejectAmount], [Discount], [PayAmount], [EstShipDate],
[ShipQty], [ShipAmount], [Remark], [SourceBillNo], [BalaPrice], [CancelQty], [Discount2]
FROM [Sal_OrderDetail]''
)SELECT [CompanyCode], [BillNo], [Sequence], [SourceBillSequence], [MaterialCode],
[BatchNo], [BoxCode], [BoxQty], [Price], [CostPrice], [Qty], [StockQty],
[StockAmount], [RejectQty], [RejectAmount], [Discount], [PayAmount], [EstShipDate],
[ShipQty], [ShipAmount], [Remark], [SourceBillNo], [BalaPrice], [CancelQty], [Discount2]
FROM '+@DataBaseName+'.[dbo].[Sal_OrderDetail]
WHERE Billno in (
Select Billno from '+@DataBaseName+'.[dbo].[Sal_OrderMaster] WHERE Yearno='''+@Yearno+''' and SeasonCode='''+@SeasonCode+''' and SourceBilltype='''+@SourceBilltype+''' )
')
--Sal_OrderSize导出
print 'Sal_OrderSize导出'
exec('insert into openrowset(''Microsoft.Jet.OLEDB.4.0'','''+@filename+''';'''+@AccessUser+''';'''+@AccessPassword+''',
''SELECT [CompanyCode], [BillNo], [Sequence], [MaterialCode], [SizeCode], [Qty],
[StockQty], [RejectQty], [ShipQty], [CancelQty]
FROM [Sal_OrderSize]''
) SELECT [CompanyCode], [BillNo], [Sequence], [MaterialCode], [SizeCode], [Qty],
[StockQty], [RejectQty], [ShipQty], [CancelQty]
FROM '+@DataBaseName+'.[dbo].[Sal_OrderSize]
WHERE Billno in (
Select Billno from '+@DataBaseName+'.[dbo].[Sal_OrderMaster] WHERE Yearno='''+@Yearno+''' and SeasonCode='''+@SeasonCode+''' and SourceBilltype='''+@SourceBilltype+''' )
')