Skip to content
Advertisement

String formatting issue for creating the SQL query for BCP

I want to use some of the static data to the new BCP query and export the extracted data to CSV. The static data are generated as a result after running some BCP command earlier.

But I have been facing string formatting issue for creating the SQL query using those variables and generate a SQL command.

I simply want to use the following query in the BCP command:

BCP query I have used is:

The above command is generating the following sql command:

and giving the error as:

I wanted to export the value of @version and @TotalRecords into the CSV file.

But I am stuck in a string formatting issue for creating the SQL query as the string.

Advertisement

Answer

Give the column a name, and output the value in quotes. Use consecutive single quotes to pass a quote to the string:

This should then output:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement