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
 Transact-SQL (2000)
 BCP Problem

Author  Topic 

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-03-25 : 14:59:38
Today is my first day playing with BCP.
I'm able to spit out files for simple "SELECT * FROM Table" queries. The query below gives me the error below. I KNOW the SQL works. I can take that same query and run it in QA and get the desired results.

Query:

DECLARE @FileName varchar(50),
@bcpCommand varchar(2000)

SET @FileName = REPLACE('c:\Customer_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')

--SET @bcpCommand = 'bcp "SELECT * FROM TeleVoxASP..Account " queryout "'
SET @bcpCommand = 'bcp "SELECT a.[ID], c.[ID], c.[Name] FROM TeleVoxASP..Customer c INNER JOIN Account a ON a.[ID] = c.AccountID " queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -S dev\sql2k -U myusername -P mypassword -n'

SELECT @bcpCommand

EXEC master..xp_cmdshell @bcpCommand


Output Error:

SQLState = S0022, NativeError = 207
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'ID'.
SQLState = S0022, NativeError = 207
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'ID'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
NULL


Any help would be appreciated. I think I might need a format file, but the doc's don't really indicate that.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-25 : 15:01:27
Put the query in a view. bcp the view out.

Tara
Go to Top of Page
   

- Advertisement -