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)
 BCP command executing a stored procedure

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-08-06 : 18:38:37
When I try to execute my stored procedure within the context of BCP I get the error message that the sp cannot be found.
Outside of the BCP command it works just fine. Any ideas why?

Works:
EXEC sp_myproc '0123,0234,0345'

Doesn't work:
EXEC xp_cmdshell 'bcp "EXEC sp_myproc ''0123,0234,0345''" queryout "C:\test.txt" -T -c '

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-06 : 18:46:37
EXEC xp_cmdshell 'bcp "EXEC YourDatabaseNameGoesHere.dbo.sp_myproc ''0123,0234,0345''" queryout "C:\test.txt" -T -c '

Also, you should be aware of the performance hit you'll get with a stored procedure prefixed with sp_. You should never use sp_ as a prefix except for system stored procedures as SQL Server will automatically check the master database first for your object and then in your database. It's a small performance hit, but it's so simple to correct that it's worth doing.

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

Subscribe to my blog
Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-08-06 : 19:05:38
Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-07 : 00:38:20
You're welcome.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -