Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error with SQL Server 2008 stored procedure bcp

Posted on 2013-12-19
5
Medium Priority
?
718 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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