易截截图软件、单文件、免安装、纯绿色、仅160KB

使用SQL Server导入/导出Excel

使用SQL Server导入/导出Excel,包含部分错误信息处理方法;
操作手记,留此备查
/*
导入
*/
--错误信息如下时:
--Msg 15281, Level 16, State 1, Line 2
--SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
--请选择执行下面语句,修改默认配置,在进行导入操作
-- begin
sp_configure 'show advanced options',1
RECONFIGURE WITH override
go
sp_configure 'Ad Hoc Distributed Queries',1 -- 1:启用,默认0:禁用
RECONFIGURE WITH override
go
EXEC sp_configure;
go
-- end
-- 查询
select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=D:\ExcelSheet1.xls',sheet1$)
go
-- 查询并导入
select * into ExcelSheet from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=D:\ExcelSheet1.xls',sheet1$)
go
/*
导出
*/
--错误信息如下时:
--Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
--SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.
--请选择执行下面语句,修改默认配置,在进行导出操作
-- begin
sp_configure 'show advanced options',1
RECONFIGURE WITH override
go
sp_configure 'xp_cmdshell',1 -- 1:启用,默认0:禁用
RECONFIGURE WITH override
go
EXEC sp_configure;
go
-- end
--添加到现在Excel文档
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=D:\ExcelSheet.xls',sheet1$)
go
--带连接信息导出
EXEC master..xp_cmd


相关文档:

SQL SERVER的分类汇总

SQL SERVER的分类汇总
SQL SERVER中使用GROUP BY对数据进行分类汇总,我们也可以使用WITH ROLLUP和WITH CUBE配合GROUP BY进行“增强”了的分类汇总,那么他们两个是如何增强GROUP BY的汇总能力的呢?
一.功能增强
1.使用WITH ROLLUP
用下面的例子说明,GROUP使用了3个分组字段:GROUP BY A, B, C WITH ROLLUP ......

SQL Server 2008的四项新特性

在SQL Server 2008中,不仅对原有性能进行了改进,还添加了许多新特性,比如新添了数据集成功能,改进了分析服务,报告服务,以及Office集成等等。
  SQL Server集成服务
 
 SSIS(SQL Server集成服务)是一个嵌入式应用程序,用于开发和执行ETL(解压缩、转换和加载)包。SSIS代替了SQL
2000的DTS。整合服务功能既包 ......

sql server日期时间函数

Sql Server中的日期与时间函数
1.  当前系统日期、时间
    select getdate() 
2. dateadd  在向指定日期加上一段时间的基础上,返回新的 datetime 值
   例如:向日期加上2天
   select dateadd(day,2,'2004-10-15')  --返回:2004-10-17 00:00:00.000 ......

ASP.NET中treeview应用(用SQL作数据源)


treeview.aspx中代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="treeview.aspx.cs" Inherits="treeview" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号