Hello all,
Background:
I've posted a couple questions recently regarding using BCP to extract
many tables to text files. I've written an extract application that
bcp's about 100 tables from a database to text files. I've run into a
couple limitations using BCP, but I finally landed on (what I thought)
was a solid solution. I now call bcp passing a sproc name and a
parameter or two and having that sproc execute the query for me,
thereby doing the extracts to the proper files.
Background-Detail:
The sproc that executes the query seems to be working just fine for
all but a couple tables. I have a need for extracting files in a
particular format (quoted and pipe-delimited, with quoted and piped
column headers as the first row in the resulting file), and that's
what my sproc does. For a given table name, I select all the columns
and interrogate their column type (systype) and wrap the proper
formatting around the particular field value (i.e. "|" + field_name +
"|"). After building the proper SQL query, I execute it and the
results are bcp'd to the specified extract file.
Issue:
For some reason, any table that contains a bit field as the last field
in the table design, BCP cannot execute the query, claiming there's a
syntax error near the end of my query (unclosed quotation mark). For
bit field types in SQL Server, the select query that I build for the
format of the extract involves a SELECT..CASE statement to convert a 1
to TRUE and 0 to FALSE. The odd thing is that the query that is built
in the sproc will work just fine in SQL Query Analyzer, as well as
just putting the desired query in a varchar variable in a sproc
(without building it by looking up field types) and executing it via
BCP. BCP only croaks when I run the sproc as designed and the final
field selected in the generated query has a type of 'bit'. There are
other tables that contain bit fields and BCP seems to run the extract
queries just fine for those instances. The only difference being that
those table designs don't contain a bit field as the last field.
It's a tough thing to accurately describe, so please reply with
further questions, and I'll try to help you better understand. But the
root issue is that the SAME EXACT query will work in query analyzer as
well as a stored procedure, but not when executing the stored
procedure via BCP.
Anyone seen this type of inconsistency using BCP?
Thanks for any help on this one.
/bc
Background:
I've posted a couple questions recently regarding using BCP to extract
many tables to text files. I've written an extract application that
bcp's about 100 tables from a database to text files. I've run into a
couple limitations using BCP, but I finally landed on (what I thought)
was a solid solution. I now call bcp passing a sproc name and a
parameter or two and having that sproc execute the query for me,
thereby doing the extracts to the proper files.
Background-Detail:
The sproc that executes the query seems to be working just fine for
all but a couple tables. I have a need for extracting files in a
particular format (quoted and pipe-delimited, with quoted and piped
column headers as the first row in the resulting file), and that's
what my sproc does. For a given table name, I select all the columns
and interrogate their column type (systype) and wrap the proper
formatting around the particular field value (i.e. "|" + field_name +
"|"). After building the proper SQL query, I execute it and the
results are bcp'd to the specified extract file.
Issue:
For some reason, any table that contains a bit field as the last field
in the table design, BCP cannot execute the query, claiming there's a
syntax error near the end of my query (unclosed quotation mark). For
bit field types in SQL Server, the select query that I build for the
format of the extract involves a SELECT..CASE statement to convert a 1
to TRUE and 0 to FALSE. The odd thing is that the query that is built
in the sproc will work just fine in SQL Query Analyzer, as well as
just putting the desired query in a varchar variable in a sproc
(without building it by looking up field types) and executing it via
BCP. BCP only croaks when I run the sproc as designed and the final
field selected in the generated query has a type of 'bit'. There are
other tables that contain bit fields and BCP seems to run the extract
queries just fine for those instances. The only difference being that
those table designs don't contain a bit field as the last field.
It's a tough thing to accurately describe, so please reply with
further questions, and I'll try to help you better understand. But the
root issue is that the SAME EXACT query will work in query analyzer as
well as a stored procedure, but not when executing the stored
procedure via BCP.
Anyone seen this type of inconsistency using BCP?
Thanks for any help on this one.
/bc
Comment