May 15, 2006 at 1:56 pm
Yes, this question about good old BCP.
I need to BCP out a table along with column names. Is it possible with BCP or is there a workaround for this?
May 15, 2006 at 3:59 pm
I've seen it done by inserting all the data into a global temporary table (## prefix) like this:
CREATE TABLE ##tmp_table (
id_field INT IDENTITY(1,1)
,column1VARCHAR ( 50 )
,column2 VARCHAR ( 50 )
)
INSERT ##tmp_table (column1, column2)
VALUES ('Column1', 'Column2')
INSERT ##tmp_table (column1, column2)
VALUES (REPLICATE('-', 50), REPLICATE('-', 50))
INSERT ##tmp_table (column1, column2)
SELECT CONVERT(VARCHAR, column1), CONVERT(VARCHAR, column2)
FROM table
... then you bcp out the table using the query "SELECT * FROM ##tmp_table ORDER BY id_field ASC". It works, but it looks like a bit of a hack.
May 15, 2006 at 4:02 pm
I am not sure if this is what you need, but when running interactive BCP, by NOT specifying any of the format arguments (-f, -c, -n, -w, -N, -V) BCP will prompt for formatting information. Respond to the prompts and you can save the format information to a format file, which also contain the table column names.
May 16, 2006 at 10:37 am
You might want to search the forums ... I seem to remember a 'cool' solution that used a VIEW with a 'UNION ALL' in it that does just what you need.
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply