New Features Open Serverâ„¢ 15.0 and SDK 15.0 for Microsoft Windows, Linux. The discard file is created by appending the input file name to the discard file. The bcp logs all the rows from the beginning of the batch until the failed row. As we already know, how to use bcp to export data from sql server. BCP is largely known command for importing data in sql server as well as exporting data from sql server. Here you will see by using bcp command, we will import data in sql server table. You can execute the bcp command either on command prompt or using xpcmdshell in stored.
![Unable To Open Input File In Bcp Unable To Open Input File In Bcp](/uploads/1/2/5/6/125632194/688786327.png)
bcp 'select count('field1_id') from table_name_here where field2_id='50' queryout S:queriestest.txt -S [servername] -U [user] -P [password] -c
And we get this:
SQLState = S0002, NativeError = 208
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'table_name_here'.
SQLState = 37000, NativeError = 8180
![File File](/uploads/1/2/5/6/125632194/740253627.png)
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
This doesn't surprise me as we have multiple databases on our SQL server, and the syntax above doesn't show where the database name could be defined. So I need to know how to point this query to the right database. That's my main question.
HOWEVER...
Since time is of the essence I chose BCP because it seemed to have a simpler syntax than DTS for a new user. I need this text file output to be formatted in a specific way (specifically, with a variable name inserted in front of the output so another program can suck in that data). Can DTS be called from the command line, and thus from a batch file? If so, what is the syntax for a DTS command that matches the above BCP command, but adds a text string in front of the data?