SQL导出数据到EXCEL文件
来源:互联网 发布:活跃用户大数据 编辑:程序博客网 时间:2024/05/03 03:23
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
CreateXLSfromT-SQL
---------------------------------------------------------------------------
--CreateXLSscriptDAL-04/24/2003
--
--DesignedforAgentscheduling,turnon"Appendoutputforstephistory"
--
--Searchfor%%%tofindadjustableconstantsandotheroptions
--
--UsesOLEforADOandOLEDBtocreatetheXLSfileifitdoesnotexist
-- LinkedserverrequirestheXLStoexistbeforecreation
--UsesOLEADOtoCreatetheXLSWorksheetforuseasatablebyT-SQL
--UsesLinkedServertoallowT-SQLaccesstoXLStable
--UsesT-SQLtopopulateteXLSworksheet,veryfast
--
PRINT'BeginCreateXLSscriptat'+RTRIM(CONVERT(varchar(24),GETDATE(),121))+''
PRINT''
GO
SETNOCOUNTON
DECLARE@Connint--ADOConnectionobjecttocreateXLS
,@hrint--OLEreturnvalue
,@srcvarchar(255)--OLEErrorSource
,@descvarchar(255)--OLEErrorDescription
,@Pathvarchar(255)--DriveorUNCpathforXLS
,@Connectvarchar(255)--OLEDBConnectionstringforJet4EXCELISAM
,@WKS_Createdbit--WhethertheXLSWorksheetexists
,@WKS_Namevarchar(128)--NameoftheXLSWorksheet(table)
,@ServerNamenvarchar(128)--LinkedServernameforXLS
,@DDLvarchar(8000)--Jet4DDLfortheXLSWKStablecreation
,@SQLvarchar(8000)--INSERTINTOXLST-SQL
,@Recsint--NumberofrecordsaddedtoXLS
,@Logbit--Whethertologprocessdetail
--Initvariables
SELECT@Recs=0
--%%%1=Verboseoutputdetail,helpsfindproblems,0=minimaloutputdetail
,@Log=1
--%%%assigntheUNCorpathandnamefortheXLSfile,requiresRead/Writeaccess
-- mustbeaccessablefromserverviaserviceaccount
-- &SQLServerAgentserviceaccount,ifscheduled
SET@Path='C:/TEMP/Test_'+CONVERT(varchar(10),GETDATE(),112)+'.xls'
--assigntheADOconnectionstringfortheXLScreation
SET@Connect='Provider=Microsoft.Jet.OLEDB.4.0;DataSource='+@Path+';ExtendedProperties=EXCEL8.0'
--%%%assigntheLinkedServernamefortheXLSpopulation
SET@ServerName='EXCEL_TEST'
--%%%RenameTableasrequired,thiswillalsobetheXLSWorksheetname
SET@WKS_Name='People'
--%%%TablecreationDDL,usesJet4syntax,
-- Textdatatype=varchar(255)whenaccessedfromT-SQL
SET@DDL='CREATETABLE'+@WKS_Name+'(SSNText,NameText,PhoneText)'
--%%%T-SQLfortablepopulation,notethe4partnamingrequiredbyJet4OLEDB
-- INSERTINTOSELECT,INSERTINTOVALUES,andEXECsptypesaresupported
-- LinkedServerdoesnotsupportSELECTINTOtypes
SET@SQL='INSERTINTO'+@ServerName+'...'+@WKS_Name+'(SSN,Name,Phone)'
SET@SQL=@SQL+'SELECTau_idASSSN'
SET@SQL=@SQL+',LTRIM(RTRIM(ISNULL(au_fname,'''')+''''+ISNULL(au_lname,'''')))ASName'
SET@SQL=@SQL+',phoneASPhone'
SET@SQL=@SQL+'FROMpubs.dbo.authors'
IF@Log=1PRINT'CreatedOLEADODB.Connectionobject'
--CreatetheConnobject
EXEC@hr=sp_OACreate'ADODB.Connection',@ConnOUT1<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
CreateXLSfromT-SQL
---------------------------------------------------------------------------
--CreateXLSscriptDAL-04/24/2003
--
--DesignedforAgentscheduling,turnon"Appendoutputforstephistory"
--
--Searchfor%%%tofindadjustableconstantsandotheroptions
--
--UsesOLEforADOandOLEDBtocreatetheXLSfileifitdoesnotexist
-- LinkedserverrequirestheXLStoexistbeforecreation
--UsesOLEADOtoCreatetheXLSWorksheetforuseasatablebyT-SQL
--UsesLinkedServertoallowT-SQLaccesstoXLStable
--UsesT-SQLtopopulateteXLSworksheet,veryfast
--
PRINT'BeginCreateXLSscriptat'+RTRIM(CONVERT(varchar(24),GETDATE(),121))+''
PRINT''
GO
SETNOCOUNTON
DECLARE@Connint--ADOConnectionobjecttocreateXLS
,@hrint--OLEreturnvalue
,@srcvarchar(255)--OLEErrorSource
,@descvarchar(255)--OLEErrorDescription
,@Pathvarchar(255)--DriveorUNCpathforXLS
,@Connectvarchar(255)--OLEDBConnectionstringforJet4EXCELISAM
,@WKS_Createdbit--WhethertheXLSWorksheetexists
,@WKS_Namevarchar(128)--NameoftheXLSWorksheet(table)
,@ServerNamenvarchar(128)--LinkedServernameforXLS
,@DDLvarchar(8000)--Jet4DDLfortheXLSWKStablecreation
,@SQLvarchar(8000)--INSERTINTOXLST-SQL
,@Recsint--NumberofrecordsaddedtoXLS
,@Logbit--Whethertologprocessdetail
--Initvariables
SELECT@Recs=0
--%%%1=Verboseoutputdetail,helpsfindproblems,0=minimaloutputdetail
,@Log=1
--%%%assigntheUNCorpathandnamefortheXLSfile,requiresRead/Writeaccess
-- mustbeaccessablefromserverviaserviceaccount
-- &SQLServerAgentserviceaccount,ifscheduled
SET@Path='C:/TEMP/Test_'+CONVERT(varchar(10),GETDATE(),112)+'.xls'
--assigntheADOconnectionstringfortheXLScreation
SET@Connect='Provider=Microsoft.Jet.OLEDB.4.0;DataSource='+@Path+';ExtendedProperties=EXCEL8.0'
--%%%assigntheLinkedServernamefortheXLSpopulation
SET@ServerName='EXCEL_TEST'
--%%%RenameTableasrequired,thiswillalsobetheXLSWorksheetname
SET@WKS_Name='People'
--%%%TablecreationDDL,usesJet4syntax,
-- Textdatatype=varchar(255)whenaccessedfromT-SQL
SET@DDL='CREATETABLE'+@WKS_Name+'(SSNText,NameText,PhoneText)'
--%%%T-SQLfortablepopulation,notethe4partnamingrequiredbyJet4OLEDB
-- INSERTINTOSELECT,INSERTINTOVALUES,andEXECsptypesaresupported
-- LinkedServerdoesnotsupportSELECTINTOtypes
SET@SQL='INSERTINTO'+@ServerName+'...'+@WKS_Name+'(SSN,Name,Phone)'
SET@SQL=@SQL+'SELECTau_idASSSN'
SET@SQL=@SQL+',LTRIM(RTRIM(ISNULL(au_fname,'''')+''''+ISNULL(au_lname,'''')))ASName'
SET@SQL=@SQL+',phoneASPhone'
SET@SQL=@SQL+'FROMpubs.dbo.authors'
IF@Log=1PRINT'CreatedOLEADODB.Connectionobject'
--CreatetheConnobject
EXEC@hr=sp_OACreate'ADODB.Connection',@ConnOUT1<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- SQL导出数据到EXCEL文件
- SQL导出数据到EXCEL文件
- 从SQL导出数据到Excel
- sql server导出数据到Excel
- SQL导入/导出数据到excel
- SQL导入/导出数据到excel
- SQL导出数据到EXCEL的问题
- c#sql数据导出到excel
- C#导出Excel|导出数据到Excel模板文件里
- 将页面数据导出到excel文件
- 将页面数据导出到excel文件
- GridView 数据导出到 Excel文件
- 用PlSql导出数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- 导出CListCtrl控件数据到Excel文件
- 导出CListCtrl控件数据到Excel文件
- 导出SQLServer数据到Excel文件中
- 2005Beta2概览
- SQL注入(SQLInjection)攻击现象与防范
- 在控制台打印输出九九乘法口诀表
- 新一代网络模式Web 2.0火爆发展
- 大型服务器:伸缩性、可用性与易管理性
- SQL导出数据到EXCEL文件
- 控制台打印出所有的“水仙花数”
- B/S超越C/S软件的优势在哪里?(转贴)但是不代表本人同意该文的观点,只不过想了解一些b/s的优势
- sqlserver关于函数中如何使用Getdate()(转贴)
- 显示表的详细信息(数据类型,长度,默认值等)
- 求1到20的阶乘之和
- 在SQL和ERWIN中用自定义类型、规则和默认值实现check约束从而保证数据的完整性
- 在ERwin中建立域所涉及到的SQL2000的相关知识
- 利用jxl实现excel操作