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 2005 Forums
 Transact-SQL (2005)
 Undefined error with bcp command

Author  Topic 

trackjunkie
Starting Member

31 Posts

Posted - 2010-01-08 : 15:31:38
I have a simple table with one row containing two values. I'm trying to use a bcp command to outout the contents of that row to a .csv file. I want the file to be created by the stored proceddure at runtime. I have:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[Flex_CreateCSV]

AS
BEGIN

declare @sql varchar(8000)

select @sql = 'bcp FlexApp.Flex_DataWatchTable.* format D:\Temp\LabelPrintEvent.csv -c -t -T -S' + @@servername

exec master..xp_cmdshell @sql

END

When I execute I get:
"An error occured while proicessing to command line."

There is not other information. Can anyone see what I did wrong?
This is my first stab at a bcp, so I imagine it could be a lot of things.

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-08 : 15:58:40
If you replace + @@servername with the actual server name does it run ok?

EDIT: Also it lookes liek you forgot a space-

select @sql = 'bcp FlexApp.Flex_DataWatchTable.* format D:\Temp\LabelPrintEvent.csv -c -t -T -S ' + @@servername

After the -S

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-08 : 16:00:25
SET @SqlCmd = 'bcp "SELECT * FROM database.schema.table" queryout "D:\Temp\LabelPrintEvent.csv " -c -T';



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-08 : 17:04:19
Why do you have an asterisk in your bcp command?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -