Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 bcp errors

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-03 : 09:48:36
Joel writes "SQL Server 2000
logged on as 'sa'


create table TESTTABLE (CUSTID char(15), CUST char(65))
go
insert TESTTABLE select 'CUST1','Customer One'
go
DECLARE @FileName varchar(50),
@bcpCommand varchar(2000)
SET @FileName = 'c:\TESTOUT.csv'
SET @bcpCommand = 'bcp "SELECT CUSTID, CUST FROM TESTTABLE" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P -c -t \,'
select @bcpCommand
SELECT CUSTID, CUST FROM TESTTABLE
EXEC master..xp_cmdshell @bcpCommand

I get the following results

bcp "SELECT CUSTID, CUST FROM TESTTABLE" queryout "c:\TESTOUT.csv" -U sa -P -c -t \,

CUSTID CUST
--------------- ------------------------------------------------
CUST1 Customer One

output
---------------------------
SQLState = S0002, NativeError = 208
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'TESTTABLE'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
NULL


What is invalid about this??"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-04-03 : 09:48:36
Yeah, I've had the same problem :) xp_cmdshell is running this script in the default database. It basically logs in again. There's a bcp parameter to specify the database or you can

SELECT CUSTID, CUST FROM database..TESTTABLE
Go to Top of Page
   

- Advertisement -