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
 General SQL Server Forums
 New to SQL Server Programming
 BCP QueryOut

Author  Topic 

Jgries
Starting Member

17 Posts

Posted - 2011-12-02 : 15:09:32
I'm having trouble executing the BCP QueryOut Function, below is my script and error I'm receiving.

Query:

DECLARE @Cmd varchar(8000)
SET @Cmd= 'bcp "SELECT P.ProjectName AS [@ProjectName],P.ProjectCity
AS [@ProjectCity],P.ProjectState AS [@ProjectState],[@ArchName] = (SELECT CompanyName + '', '' FROM dbo.Company AS C WHERE C.ProjectID = ProjectID FOR XML PATH('''')),DT.DocumentText FROM dbo.DocumentText AS DT JOIN dbo.DocumentProperty AS DP ON DT.DocumentPropertyID = DP.DocumentPropertyID JOIN dbo.Project AS P ON DP.ProjectID = P.ProjectID FOR XML PATH (''Doc'')" queryout C:\SQLXML\test.xml -S JGRIES-SP-5139 -T -c'
EXEC xp_cmdshell @Cmd

Error Message:
---------

SQLState = S0002, NativeError = 208
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'dbo.DocumentText'.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared.
NULL


Any help is appreciated, thank you.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-12-02 : 15:47:33
You have use 3-part names including the database name when using bcp:

...FROM myDatabase.dbo.DocumentText JOIN myDatabase.dbo.DocumentProperty...
Go to Top of Page

Jgries
Starting Member

17 Posts

Posted - 2011-12-02 : 15:50:27
I'm a little unclear what you mean, my database name is DBO, do I need to include the server name?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-12-02 : 20:30:48
No, I mean the name of the database where the tables are stored. 3-part names take the form of "Database.schema.object". dbo is the default schema for SQL server objects. For example, if they were in the Adventureworks database:

...FROM Adventureworks.dbo.DocumentText JOIN Adventureworks.dbo.DocumentProperty...
Go to Top of Page
   

- Advertisement -