SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF EXISTS ( SELECT * FROM sysobjects WHERE name = 'generateCSV' ) DROP procedure dbo.generateCSV GO CREATE procedure dbo.generateCSV ( @table varchar(100), @output varchar(100), -- u formatu @date varchar(12), @username varchar(20), @password varchar(100), @server varchar(30) ) AS DECLARE @sql varchar(8000) SELECT @sql = 'bcp "select * from ' + DB_NAME() + '..' + @table + ' where reportingdate = ''' + @date + '''"' + ' queryout ' + @output + ' -c - C65001 -t"; " -r"\n" -U' + @username + ' -P' + @password + ' -S' + @server - -+ @@servername exec master..xp_cmdshell @sql GO -- main procedure call --EXEC dbo.generateCSV @table = 'Clients', @date = '2017-10-31', @output = --'E:\Test.csv', @username = 'user', @password = 'pass', @server = -- '172.17.16.101'
I am connected via Management Studio to 172.17.16.102(server 1),to WBANKA_POBA database. I have a table Clients there and I have to export this table to some shared folder on 172.17.16.101(server 2). This procedure is tested on localhost and it is working just fine.
I receive Invalid object name WBANKA_POBA..Clients:
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name ‘WBANKA_POBA ..Clients’.
Of course that I created the table on WBANKA_POBA.
What am I missing ?