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 2000 Forums
 Import/Export (DTS) and Replication (2000)
 using bcp in stored procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-09 : 10:06:36
Ralph writes "i'm trying to use xp_cmdshell to execute a command using bcp within a stored procedure.

the command i'm trying to execute runs fine from the command line but when i try to run it within the stored procedure, i get the following error:
"'bcp' is not recognized as an internal or external command,
operable program or batch file."
I get a similar error trying other methods like osql.

i've checked the PATH variable and it contains the directory in which the bcp.exe program sits.

Here's my code to examine.

select @bcpCommand = 'bcp "database..table" out "c:\file.txt" -U user -P pass -c '
EXEC master.dbo.xp_cmdshell @bcpCommand

Thanks in advance."

efelito
Constraint Violating Yak Guru

478 Posts

Posted - 2002-01-09 : 16:44:35
Specify the entire path and it should work fine. The PATH variable is different for the service account that sql uses to run the command on the OS than when you are logged in as yourself. You should never rely on path variables to run your executeables. Try your command like this.

select @bcpCommand = 'c:\mssql7\binn\bcp.exe "database..table" out "c:\file.txt" -U user -P pass -c '
EXEC master.dbo.xp_cmdshell @bcpCommand



Jeff Banschbach
Consultant, MCDBA
Go to Top of Page

muhiar
Starting Member

37 Posts

Posted - 2006-04-27 : 11:44:20
hi
i have tried your solution but it does not work
it keeps telling me that 'bcp' is not recognized as an internal or external command,
operable program or batch file."

although the same command works from the command prompt when i work from the
c:\Program File\microsoft SQL Server\80>> bcp

Go to Top of Page
   

- Advertisement -