I am trying to execute a really simple SQL select query to file as it is on a 3rd party suppliers DB hosted in SQL Express with no SSIS.
I have written the select query & tested this runs within SSMS without any issue at all.
I have had a nightmare however trying to get BCP to run in a command prompt. I have tried running from my local machine, running on a network drive, even adding the .bat file to the tools/binn dir of SQL server as advised elsewhere on line.
The error I get now flashes up very quickly so I had to grab a quick screenshot before it closed the cmd window as per below:
I have also tried running from a scheduled task on the server but this produced different error codes within the servers error logs.
This is the last piece in a wider project & I don't have much experience with .bat files so any suggestions would be greatly appreciated.
The bat file looks like the below (passwords replaced with XX - Excuse the long query. I need to create a file that has an exact number of sections for the import inot a 3rd party systerm to work so added numbers to easily count fields).
BCP "SET NOCOUNT ON; SELECT '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + [sender_reference] + '|' + '|' + '|' + '|' + (REPLACE(CONVERT(CHAR(15), manifest_dt, 103),' ',' - ')) + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + '|' + [airwaybill_num] + '|' + '|' + '|' + '|' + '|' + '|'FROM airwaybills_history WHERE manifest_dt between (SELECT Convert(DateTime, DATEDIFF(DAY, 0, GETDATE()))) and (GETDATE()) + '23:59:59''" QUERYOUT \\carrier\test-file\test.OUT -S CARRIER\DHLEASYSHIP -U xx -P xx -c