question

PadmanabhanVenkatesh-6789 avatar image
0 Votes"
PadmanabhanVenkatesh-6789 asked MelissaMa-msft edited

BCP data extract issue

Hi.
I am trying to use BCP command in a C# console application.

The sql query is as below:

BCP "SELECT 1 as First, [IDENTITY], QUOTENAME(columnName,'""') from tablename" queryout "C:\Data\FILEname.del" -T -S Server -d DBInstance -b 500 -c -C 65001 -t~

since the query contains [] , the bcp returns no rows. Directly running this in SQL, rows are shown in results.

How to fix this ?

sql-server-generaldotnet-csharpsql-server-transact-sql
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@PadmanabhanVenkatesh-6789,

Please update your question and share your c# code.

0 Votes 0 ·

Post your query which works in SSMS.

0 Votes 0 ·

1 Answer

ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered

What do you mean "with returns no rows". BCP never returns any rows, it writes to a file.

Why do think that the brackets are a problem?

I do spot an issue in your command though. The double quotes you pass to quotename can cause problems with the command-line window. Change this to:

QUOTENAME(columnName, char(34))

Beware that the quotename function will return NULL if the input exceeds 128 characters!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.