|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SQLCMD vs BCPI have the following BCP bcp.exe "SELECT * FROM LAW.dbo.A" queryout "C:\Test\Test.txt" -c -q -C1252 -T -S "SEA2-LawrenceB1" -t "," Current ResultSet (3 columns - 2 varchar, 1 int) Seattle,Lawrence,1 New York,Jeanette,2 However, my issue is that BCP DOES NOT include Header in ResulSet. Ideal ResultSet (first row is Header) City,Name,Num Seattle,Lawrence,1 New York,Jeanette,2 I would like to use SQLCMD to include Header info. However I am not able to find the correct switches to accomplish this. The current format which I DO NOT desire includes - "..........." on the second time, "<rows> are effected" message is returend. Let me know if any of you could help me with this ideal format in SQLCMD or OSQL. Thanks, -Lawrence Lawrence (Lawre***@discussions.microsoft.com) writes:
Show quote > I have the following BCP You would have to write the column names to a seprate file and > bcp.exe "SELECT * FROM LAW.dbo.A" queryout "C:\Test\Test.txt" -c -q -C1252 > -T -S "SEA2-LawrenceB1" -t "," > > Current ResultSet (3 columns - 2 varchar, 1 int) > > Seattle,Lawrence,1 > New York,Jeanette,2 > > However, my issue is that BCP DOES NOT include Header in ResulSet. > > Ideal ResultSet (first row is Header) > City,Name,Num > Seattle,Lawrence,1 > New York,Jeanette,2 then concatenate those file with COPY. > I would like to use SQLCMD to include Header info. However I am not The "rows affected" is simple to deal with: SET NOCOUNT ON. The dashes> able to find the correct switches to accomplish this. The current > format which I DO NOT desire includes - "..........." on the second > time, "<rows> are effected" message is returend. below the headers are more difficult to deal with. However, with -h-1 you can suppress them entirely. You also need to use -s to set the column separator and -W to trim spaces. You could do as I suggested above, and write the header to a file separately. You could then use >> to append output from SQLCMD to that file. This can be more effecient than concatenating two files, the amount of data is huge. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
|||||||||||||||||||||||