April 5, 2005 at 2:51 pm
Hey all, I'm in report generating mode for a project. I BCP output data for the different "reports" I've generated. Is there a way to include the column headers in my flat file extract? (Instead of having just raw data).
(Cannot use DTS, etc..)
April 5, 2005 at 6:10 pm
try isqlw.
You can change default session setting by making changes in sql query analyzer.
April 5, 2005 at 11:06 pm
I believe ISQLW will launch Query Analyzer. I think you meant ISQL and it is fairly well deprecated compared to OSQL. That, not withstanding, if you use OSQL to run a query (as wz700 eluded to), you can direct the output to a file using either the -o switch or the ">" redirection character. You will also get those pesky dashed lines unless you get clever by turning off the headers and using a UNION to select headers followed by data.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 6, 2005 at 5:19 am
I mean isqlw.
Try this.
save following sql to file (test.sql)
select * from pubs.dbo.authors
Change default session setting
open sql query analyzer, Tools/Options,
In Results tag,
tick Print column headers(*) check box.
select Comma Delimited(CSV) in Results output format*)
In Connection Properties tag,
tick set nocount check box.
Ok to close.
At dos prompt type;
isqlw -i test.sql -S(local) -E -o testout.txt
check the output file testout.txt.
You can get syntax by isqlw /?
April 6, 2005 at 12:21 pm
that's pretty stupid that you can't use DTS; it's by far the easiest way to do this.
Look in BOL under:
bcp utility, format files
bcp utility, accessing and changing data:
bcp {[[database_name.][owner].]{table_name | view_name} | "query"}
{in | out | queryout | format} data_file
[-m max_errors] [-f format_file] [-e err_file]
[-F first_row] [-L last_row] [-b batch_size]
[-n] [-c] [-w] [-N] [-V (60 | 65 | 70)] [-6]
[-q] [-C code_page] [-t field_term] [-r row_term]
[-i input_file] [-o output_file] [-a packet_size]
[-S server_name[\instance_name]] [-U login_id] [-P password]
[-T] [-v] [-R] [-k] [-E] [-h "hint [,...n]"]
Signature is NULL
April 6, 2005 at 1:18 pm
I'm running these reports on a timed basis, hence using T-SQL scripts in JOBS. DTS stinks, and is foolishly limited in what it can do. There are no format commands to include column names.
April 6, 2005 at 3:48 pm
"DTS stinks, and is foolishly limited in what it can do. There are no format commands to include column names."
Uh...OK; that's totally wrong. In DTS, the "text file (destination)" object has a property (radio button through the GUI) to include column headers or not. Simple as that.
As for running them on a "timed" basis; you can easily execute DTS from the command line using DTSRun and xp_cmdshell, or even simpler, schedule the package under SQLAgent.
DTS does not stink; it works very well for simple projects, and can be made to work for more complex projects with a little creativity and VB 101 (OK, I'll grant you that VB sucks, but at least it's really easy to program).
Using DTS I can set up a data extract/import (to staging) in under 5 minutes, good luck trying to do that with BCP.
Signature is NULL
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply