【转】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 ...
随机推荐
- Go中简单的文件读写
Go中的ioutil包可以方便的实现文件读写.代码: package main import ( "fmt" "io/ioutil" ) func main() ...
- EF之高级查询
首先我们来看看一个页面 这里面有多选的条件,大于,小于等等,包括每个字段都有 如此多的查询条件,我们的后台该如何实现呢? 难道我们还得每个参数都去判断吗? 那得传多少参数进来才能实现这个页面的功能啊! ...
- [转]Ubuntu中root用户和user用户的相互切换
[转]Ubuntu中root用户和user用户的相互切换 http://www.cnblogs.com/weiweiqiao99/archive/2010/11/10/1873761.html Ubu ...
- gcc 创建库及使用
gcc -shared hello.c -o libhello.so gcc -o test test.c -L库所在目录 -l库名
- 一、换系统wince ---到 linux ubuntu 桌面
今天终于拿到了OK6410,还是比较满意.预装的为wince系统,现要修改为linux 按照 OK6410-A开发板LINUX3.0.1-2013-01用户手册 进行 1.遇到问题.无法写入SD卡( ...
- 如何在Report Builder中使用fnd_profile.value
在EBS的Report开发中,需要根据客户化的一个Profile来控制用户可以访问的数据,可是在开发的过程中发现一直取不到该Profile的值,后来百度才找到了原因. 解决方法: 1.添加用户参数p_ ...
- 盘点Windows 8.1中隐藏着的25个秘密功能
Windows 8.1正式版问世,带来了众多大家早已耳熟能详的“开始按钮”.“分屏显示”等功能.事实上,Windows 8.1贴心的设计细节有很多,多数细节隐藏于系统中某个不起眼的角落,科技网站PC ...
- LeetCode-Data Stream as Disjoint Intervals
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- Android基础整理之四大组件Activity
最近准备系统的重新整理复习一下Android的各方面的知识,本着知识分享的原则,我就把梳理过程中一些东西给记录下来,权当一个学习笔记吧. 下面步入正题..... 什么是Activity Activit ...
- Careercup - Google面试题 - 5727310284062720
2014-05-06 14:04 题目链接 原题: given an 2D matrix M, is filled either using X or O, you need to find the ...