2008-12-05 74 views

回答

5

与queryout选项使用bcp http://msdn.microsoft.com/en-us/library/ms162802(SQL.90).aspx

bcp "SELECT * FROM AdventureWorks.Person.Contact" queryout Contacts.txt -c -T 

如果你想固定宽度输出

http://weblogs.sqlteam.com/brettk/archive/2006/07/06/10504.aspx

我只是试图在AdventureWorks的出口使用格式文件,固定宽度给了我一个很多问题(与列分隔符相比) 我不得不忽略GUID列,不在第一行包含列名等。最后导出S ales.Customer表

没有BCP,你可能不得不考虑SSIS或SQLCMD

0

如果向导的格式不符合您的需求,您需要开发自己的SSIS包。你确定你确实需要一个固定宽度的文件吗?分隔文件可能会更容易得到,因为它们更常见。

0

我发现SQL2005/SSIS只是简单的任务,看似简单的任务。事情总是让我比他们应该长5倍。我知道我并不孤单。

BCP应该工作。

不知道sqlcmd - 看起来好像没有固定宽度,除非你在你的sql语句中填充了填充 - 这也会是一个痛苦。

usage: Sqlcmd   [-U login id]   [-P password] 
    [-S server]   [-H hostname]   [-E trusted connection] 
    [-d use database name] [-l login timeout]  [-t query timeout] 
    [-h headers]   [-s colseparator]  [-w screen width] 
    [-a packetsize]  [-e echo input]  [-I Enable Quoted Identifiers] 
    [-c cmdend]   [-L[c] list servers[clean output]] 
    [-q "cmdline query"] [-Q "cmdline query" and exit] 
    [-m errorlevel]  [-V severitylevel]  [-W remove trailing spaces] 
    [-u unicode output] [-r[0|1] msgs to stderr] 
    [-i inputfile]   [-o outputfile]  [-z new password] 
    [-f <codepage> | i:<codepage>[,o:<codepage>]] [-Z new password and exit] 
    [-k[1|2] remove[replace] control characters] 
    [-y variable length type display width] 
    [-Y fixed length type display width] 
    [-p[1] print statistics[colon format]] 
    [-R use client regional setting] 
    [-b On error batch abort] 
    [-v var = "value"...] [-A dedicated admin connection] 
    [-X[1] disable commands, startup script, enviroment variables [and exit]] 
    [-x disable variable substitution] 
    [-? show syntax summary] 
相关问题