Solved

Error with SQL Server 2008 stored procedure bcp

Posted on 2013-12-19
5
686 Views
Last Modified: 2014-01-02
In Sql Server 2008 I created a stored procedure to select data from a table.  I am trying to output the results to a csv file.  When I execute it I get an error

bcp host-files must contain at least one column

My procedure is below:
CREATE procedure [dbo].[OneItemEntered]
as
begin
DECLARE @FileName varchar(200), @bcpCommand varchar(4000)
SET @FileName = REPLACE('c:\temp\OneRecord'+CONVERT(char(8),GETDATE(),1)+'.csv','/','-')
--SET @bcpCommand = 'bcp "EXEC dbo.OneRecordEntered" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -T -c'
end

Thanks!
0
Comment
Question by:newtoperlpgm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 500 total points
ID: 39731808
Hi newtoperlpgm
The stored procedure which you are supplying to the BCP command is dbo.OneRecordEntered

In SQL Server Management Studio Query window please execute
exec dbo.OneRecordEntered

and then post up the output
0
 

Author Comment

by:newtoperlpgm
ID: 39732078
BCUNNEY,
You mean post the output that I get when I execute the stored procedure?  Thank you.
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 39732386
Hi newtoperlpgm
Yes that is correct, the output that you get when you execute the dbo.OneRecordEntered stored procedure
0
 

Author Comment

by:newtoperlpgm
ID: 39732846
Alas, I realize I did not have my select statement in my procedure.  I will add and see what, if any, errors I come up with when I execute.  Thank you.
0
 

Author Comment

by:newtoperlpgm
ID: 39752477
Yup, that was my problem, I forgot to add my sql to my stored procedure.  Thank you.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question