Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I have a SQL i want this to save the output to text file
But don't know what is getting wrong
I generate error that "Invalid object name payroll..employee_v"

But when i execute the select statement it work file
And this SQL also work fine when i put this command
SELECT * FROM pubs..authors
Please help thanks

SQL
DECLARE @FileName varchar(50),
        @bcpCommand varchar(2000)

SET @FileName = 'C:\result.txt'

SET @bcpCommand = 'bcp "SELECT * FROM payroll..employee_v ORDER BY emp_no" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P 123 -c'

EXEC master..xp_cmdshell @bcpCommand
Posted
Updated 16-Jun-16 8:32am
Comments
ZurdoDev 16-Jun-16 15:04pm    
Invalid object name means just that. Try .dbo. instead of ..
Dave Kreskowiak 16-Jun-16 16:11pm    
6 year old question.
ZurdoDev 16-Jun-16 16:13pm    
I don't discriminate..... or pay much attention to the timestamp. ;)

1 solution

What happens if you try to run this command from the SQL window? This tells me that you have access to items in pubs, but not payroll.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900