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)
 about BCP utility

Author  Topic 

sqldev6
Starting Member

18 Posts

Posted - 2008-06-02 : 10:54:46
Hello, I need to create a stored procedure that creates a csv file. this is the code I have so far.


Script is like

CREATE PROCEDURE dbo.GetQuestionInfoCSV AS
BEGIN
declare @sql varchar(8000)
SET @sql = 'bcp "SELECT * FROM dbo.ISO_table" queryout C:\GetCSV.CSV -c -t, -T -S MANCHEST\SQLEXPRESS'
print @sql
EXEC master..xp_cmdshell @sql
END


and I get these errors on execution


SQLState = 42S02, NativeError = 208
Error = [Microsoft][SQL Native Client][SQL Server]Invalid object name 'dbo.ISO_table'.
SQLState = 42000, NativeError = 8180
Error = [Microsoft][SQL Native Client][SQL Server]Statement(s) could not be prepared.
NULL


Any help would much appreciated.

sqldev6
Starting Member

18 Posts

Posted - 2008-06-02 : 11:03:37
I got it.

I am not specifing database name anywhere in my code.

If we not specifing any db name it will look into the default database of that user.

Thats why its giving that error. invalid object error.


Thanks..........:)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 11:16:15
quote:
Originally posted by sqldev6

I got it.

I am not specifing database name anywhere in my code.

If we not specifing any db name it will look into the default database of that user.

Thats why its giving that error. invalid object error.


Thanks..........:)



Thanks for posting the solution too. This will certainly be of help to someone in future.
Go to Top of Page
   

- Advertisement -