Jonathan if I’ve understood your post correctly I think I’ve worked out a solution using Linked Servers.
Linked servers can be defined to point back to the themselves which MS define as a Loopback Linked Server
Take the following scenario
Your server is called NT01. Co.A has a database called DataA and Co.B has a database called DataB
Set up a Login say called LNK using SQL Server authentication with an appropriate DBA password. This login should have db_datareader access to Co.A database DataA
Run the following SQL to link the server to itself
EXEC sp_addlinkedserver @server = N'NT01_LINK',
@srvproduct = N' ',
@provider = N'SQLOLEDB',
@datasrc = N'NT01',
@catalog = N'DataA'
Where @server is the logical name you wish to call your linked server and @datasrc is the actual name of the server.
Run the following SQL to add a linked server login
EXEC sp_addlinkedsrvlogin 'NT01_LINK', 'false', NULL, 'LNK', 'Password'
Where NT01_LINK is the logical name of your linked server. LNK is the login which local users will be mapped through and Password is the appropriate DBA password you supplied earlier to user LNK.
Now create the required views in Co.B’s DataB database using fully qualified tablenames using the logical linked server name:
Create view vwForB
As
Select * from NT01_LINK.DataA.dbo.tablename
Users of Co.B database DataB will now be able to select from the views held in their own database and get the required results. They will be going through the mapped user LNK (which is secure with a DBA password) to the database DataA. They will not be able to see any tables etc with in Co.A’s DataA database.
The above scenario does work does work and I think I’ve put everything on here (barring any typos) as to how I worked round the problem. Looks a bit complicated to start with but once you have loopback linked server and login in place it will work for any future views you may wish to add.
One word of caution is the following: Loopback linked servers cannot be used in a distributed transaction. Attempting a distributed query against a loopback linked server from within a distributed transaction raises an error:
Regards
Rick