trying to create a BCP that will export data from a table to a CSV file.
I have the following code:
DECLARE @bcpCmd VARCHAR(8000)
SET @bcpCmd = 'bcp "SELECT company, address, postcode FROM tbl_ifa" queryout D:\folder\test.csv -c -t, -r -T -S SERVERNAME'
EXEC master..xp_cmdshell @bcpCmd
but get the errors:
SQLState = S0002, NativeError = 208
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'tbl_ifa'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared.
NULL
but the table tbl_ifa does exist in one of the databases on the server - do i need to specify the database somewhere as well as the servername
I have the following code:
DECLARE @bcpCmd VARCHAR(8000)
SET @bcpCmd = 'bcp "SELECT company, address, postcode FROM tbl_ifa" queryout D:\folder\test.csv -c -t, -r -T -S SERVERNAME'
EXEC master..xp_cmdshell @bcpCmd
but get the errors:
SQLState = S0002, NativeError = 208
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'tbl_ifa'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared.
NULL
but the table tbl_ifa does exist in one of the databases on the server - do i need to specify the database somewhere as well as the servername