2008-12-05 73 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] 
相關問題