Wow - time flies, I really can't beleive its been 3 weeks since I last looked at this blog. To follow up on some of the feedback I got, here is a summarey of the post I was discussing. Its a re-hash of the actual posting from OJ, but it should give you some idea.
My problem was that any stored proc that uses temp tables wouldn't return a column list when queried from a linked server, which in turn might be used as part of a view. In the following example we have to turn that behaviour of by calling set fmtonly on first. Also, the sp can return as many resultsets it wants. However, only the first will be accepted and redirected by the view. The example shows both of these facts in 'action'. e.g. use tempdbgocreate proc uspasset nocount oncreate table #tmp1(OrderID int, CustomerID sysname)create table #tmp2(EmployeeID int, Freight money) insert #tmp1select top 1 OrderID,CustomerIDfrom Northwind..Orders insert #tmp2select top 1 EmployeeID,Freightfrom Northwind..Orders select * from #tmp1select * from #tmp2go use Northwindgocreate view _vasselect *from openquery(myserver,'set fmtonly off; exec tempdb..usp')xgoselect * from _vgo drop view _vgoexec tempdb..sp_executesql N'drop proc usp'go
Openquery() opens a new connection for distributed query based on the current_user authentication/profile. By default, every login's default database is master (unless you over-ride it). Thus, the distributed connection will work under master database context. If you want to invoke an user-object (i.e. view/sp/udf/etc) from masterdatabase, you will have to qualify the database. Note that system objects (stored procedures, functions, etc.) can be called from any database, hence you wouldn't have to qualify them.
Thanks to all
Ryan