You are trying to access a temp table from the scope in which the proc executes... which is why youre having difficulty. Ive seen some people use dynamic sql or the loopback openquery method:-- this example from TechNet------------------------------- create linked server-----------------------------DECLARE @provstr varchar (2000)SET @provstr = 'PROVIDER=SQLOLEDB;SERVER=' + @@SERVERNAMEEXEC sp_addlinkedserver 'loopback', @srvproduct = 'MSSQL', @provider = 'SQLOLEDB', @provstr = @provstr------------------------------- create a test proc-----------------------------use test2gocreate procedure dbo.usp_testasset nocount onselect 1 as test_id, 'Nathan' first_name, 'Skerl' last_namego------------------------------- Create and populate table from Exec-----------------------------select * into #yourtemp from openquery (loopback, 'exec test2.dbo.usp_test')------------------------------- return results-----------------------------select * from #yourtempdrop proc usp_testdrop table #yourtemp
Nathan Skerl