【转】SQL Server T-SQL写文本文件
原文:http://www.nigelrivett.net/SQLTsql/WriteTextFile.html
The are several methods of creating text files from sql server.
- osql
- bcp
- redirection commands
- sp_MakeWebTask
- Com object calls
Remember that in all cases the path of the output file will be relative to the server - not to the client on which the application is running.
osql.
This example will just output master..sysobjects to the file c:\osqloutput.txt.
declare @cmd varchar(1000)
select @cmd = 'osql -U -P -S -Q"select * from master..sysobjects" -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd
bcp
bcp very fast and easy to use for just dumping a table out - can be used against a view too.
master..xp_cmdshell 'bcp master..sysobjects out c:\file.bcp -S -U -P -c '
redirection commands
You will need to create the data to be output as in dynamic sql statements
The first command here creates or overwrites the file - the rest append to the file.
exec master..xp_cmdshell 'echo hello > c:\file.txt'
exec master..xp_cmdshell 'echo appended data >> c:\file.txt'
exec master..xp_cmdshell 'echo more data >> c:\file.txt'
will generate a file containing
hello
appended data
more data
sp_MakeWebTask
This is for creating html code from a query
Com object calls
Using sp_oa... system stored procedures and creating com objects or existing applications you can probably do whatevr you wish - but you should probably ask whether sql server is the right place to control this.
【转】SQL Server T-SQL写文本文件的更多相关文章
- [Oracle][ODBC SQL Server Driver][SQL Server]对象名 'RECOVER.HS_TRANSACTION_LOG' 无效(转)
原帖由 qingyun 于 2010-6-21 15:44 发表 在写pl/sql的时候,有个很重要的注意点:比如:begin update 某个sqlserver的表@dblink名字 .... ...
- SQL Server经典sql语句大全(转)
一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...
- PowerDesigner反向数据库时遇到[Microsoft][ODBC SQL Server Driver][SQL Server]无法预定义语句。SQLSTATE = 37错误解决方法
逆向工程中,有时会出现如下错误 ... [Microsoft][ODBC SQL Server Driver][SQL Server]无法预定义语句 SQLSTATE = 37000 解决方案: 1. ...
- (转)[SQL Server] 动态sql给变量赋值(或返回值给变量)
本文转载自:http://blog.csdn.net/xiaoxu0123/article/details/5684680 [SQL Server] 动态sql给变量赋值(或返回值给变量) decla ...
- SQL Server 2008 /SQL Server 2008 R2 配置数据库邮件
原文:SQL Server 2008 /SQL Server 2008 R2 配置数据库邮件 从2005开始,就引入了"数据库邮件"功能.并且取代SQLMail.原有SQLMail ...
- SQL Server审计功能入门:SQL Server审核 (SQL Server Audit)
原文:SQL Server审计功能入门:SQL Server审核 (SQL Server Audit) 介绍 Audit是SQL Server 2008之后才有的功能,它能告诉你"谁什么时候 ...
- sql server 与 sql server compact 互相数据导入
从SQL Server 导出数据到 Sql Compact 使用 Sql Server Compact Tool box 从SQL Server Comapct 导出数据到 Sql Server 使 ...
- SQLSERVER 免费对比数据库结构和数据的工具支持:SQL Server 2012, SQL Server 2008 and SQL Server 2005
New xSQL Schema Compare - version 5 Compare the schemas of two SQL Server databases, review differen ...
- .NET/ASP.NET/C#/WCF/SQL Server/My SQL/Java/JSP/JDBC/Spring/Spring MVC/PHP/Python/Ruby/Shell/Agile/CSS/HTML/HTTP/Unix/Linux大量PDF书籍/电子书籍下载, Effective Java 下载
223本电子书籍,囊括了.NET/ASP.NET/C#/WCF/SQL Server/My SQL/Java/JSP/JDBC/Spring/Spring MVC/PHP/Python/Shell/A ...
- SQL Server参数化SQL语句中的like和in查询的语法(C#)
sql语句进行 like和in 参数化,按照正常的方式是无法实现的 我们一般的思维是: Like参数化查询:string sqlstmt = "select * from users whe ...
随机推荐
- CPU 材料学才是最顶级的学科
cpu的物理组成3部分:逻辑部件.寄存器.控制部件 CPU具有以下4个方面的基本功能:数据通信,资源共享,分布式处理,提供系统可靠性 cpu处理4过程:提取.解码.执行.写回 http://baike ...
- iOS学习之Object-C语言简单的通讯录管理系统
用这几天学的OC的知识,写了一个实现简单功能的通讯录管理系统,在这里分享给大家: 通讯录管理系统 * 需求: 1.定义联系人类Contact.实例变量:姓名(拼音,首字母大写).性别.电话号码.住址 ...
- 阅读verilog程序总结
1.写程序先直接写出时钟信号 //-----------------产生串行时钟scl,为输入时钟的二分频--------- always@(negedge clk)//二分频表示频率小了,周期大了 ...
- Linux C 文件与目录4 将缓冲区数据写入磁盘
将缓冲区数据写入磁盘 所谓缓冲区,是Linux系统对文件的一种处理方式.在对文件进行写操作时,并没有立即把数据写入到磁盘,而是把数据写入到缓冲区.如果需要把数据立即写入到磁盘,可以使用sync函数.用 ...
- Java程序员面试中的多线程问题
很多核心Java面试题来源于多线程(Multi-Threading)和集合框架(Collections Framework),理解核心线程概念时,娴熟的实际经验是必需的.这篇文章收集了Java线程方面 ...
- Notes of the scrum meeting(12.7)
meeting time:18:30~19:10p.m.,December 7th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- Jquery获取选中的checkbox的值
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- shell编程之环境变量
在shell编程里我们首先接触到的是环境变量,常用命令说明 1. 使用echo命令查看单个环境变量.例如: echo $PATH 2. 使用env查看所有环境变量.例如: env 3. 使用set查看 ...
- SPOJ - DQUERY 主席树
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32356 Given a sequence of n numbers ...
- USACO 4.1.2 栅栏的木料
这个讲的超好....一定要看...然后看我代码就好懂啦... http://blog.csdn.net/ta201314/article/details/41287567 各种优化确实非常好....搜 ...