sql server - SQL BCP invalid object name ##Labels -



sql server - SQL BCP invalid object name ##Labels -

i'm having problem bcp. keeps saying invalid object name ##labels despite me creating global table. doing wrong please?

the code is: -

declare @sql varchar(max) set @batchno = 'abc123' declare @test table(a varchar(max),b varchar(max),c varchar(max),d varchar(max),e varchar(max),f varchar(max),g varchar(max),h varchar(max),i varchar(max),j varchar(max)) insert @test values ('1','2','3','4','5','6','7','8','9','10') select * ##labels @test set @sql = 'select * ##labels' declare @tmpfile varchar(25) declare @folder varchar(128) declare @labeldir varchar(128) declare @template varchar(25) declare @finalfile varchar(40) declare @cmdstr varchar(300) set @tmpfile = @batchno + '.tmp' --trigger folder set @folder = '\\win-0h\labelling\xfer\' --print directive folder set @labeldir = '\\win-0h\dir\' --label info template set @template = 'cl.csv' --fine output file set @finalfile = @batchno + '.chlabel' --bulk re-create query csv temp file set @cmdstr = 'bcp "' + @sql + '" queryout ' + @folder + @tmpfile + ' -c -t "," -t' select * ##labels exec master..xp_cmdshell @cmdstr print @cmdstr --join label csv template actual info set @cmdstr = 'copy /y /b ' + @labeldir + @template + ' + ' + @folder + @tmpfile + ' ' + @folder + @finalfile exec master..xp_cmdshell @cmdstr print @cmdstr --remove temporary files set @cmdstr = 'del ' + @folder + @tmpfile exec master..xp_cmdshell @cmdstr print @cmdstr print 'im printing' drop table ##labels

the error message is:

error = [microsoft][sql server native client 11.0][sql server]invalid object name '##labels'.

the bcp command-line utility runs independently of t-sql script, when inviked via xp_cmdshell. connects default instance on same server runs on unless bcp /s parameter specifies otherwise.

in case, global temp table created on named instance script ran. however, bcp command connected default instance , global temp table did not exist there (fortunately).

sql-server tsql bcp

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -