Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bcp command from SSMS not working

Status
Not open for further replies.

2Plan

MIS
Mar 29, 2005
55
US
The following bcp command from SSMS is not working. Can someone explain why? I've attached error message below also. Thanks.

declare @sql_varchar(8000)

select @sql = 'bcp master..sysobjects out
c:\bcp\sysobjects.txt -c -t -T -S' + @@servername
exec master..xp_cmdshell @sql


Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '('.
Msg 137, Level 15, State 1, Line 3
Must declare the scalar variable "@sql".
Msg 137, Level 15, State 2, Line 5
Must declare the scalar variable "@sql".
 
Looks like you have a run-away underscore in your declare line.

[tt][blue]declare @sql[!]_[/!]varchar(8000)[/blue][/tt]

Code:
declare @sql varchar(8000)

select @sql = 'bcp master..sysobjects out 
                c:\bcp\sysobjects.txt -c -t -T -S' + @@servername
exec master..xp_cmdshell @sql

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks.

The script worked, but results were output to bottom screen of SSMS, but not the text file.

Can someone explain why?
 
Remove the line feed in the BCP command.
Code:
declare @sql varchar(8000)

select @sql = 'bcp master..sysobjects out E:\utility\sysobjects.txt -c -t -T -S' + @@servername

exec master..xp_cmdshell @sql

Terry L. Broadbent - DBA

"The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top