In particular, can I call proc from the current database in the view. I already know about openrowset hack , so this works, for example:
create view MyView as
select *
from openrowset (
'sqloledb',
'server=(local);trusted_connection=yes;',
'exec MyDatabase.dbo.MyStoredProcedure'
)
But I would like to be able to call proc from the current database without hard-coding the name like this:
create view MyView as
select *
from openrowset (
'sqloledb',
'server=(local);trusted_connection=yes;',
'exec ' + db_name() + '.dbo.MyStoredProcedure'
)
This does not work, unfortunately, since openrowset expects literal strings, not variables of any type.
Regardless of security and performance considerations, is there a workaround? This will make servicing an outdated system much more tolerant, since the proc that invokes this view connects to another database depending on the environment (dev, test, prod).