从存储过程中的另一个数据库访问表

时间:2019-02-05 15:58:16

标签: sql sql-server sql-server-2008

我有一个存储过程,其中包含一些代码,如下所示。

select count(*) as Count, datepart(yyyy, [LogDate]) as [Year]
from  ViewAssociate..Auth_Log 
where ActionCode = 1
group by datepart(yyyy, [LogDate])
order by [Year]

现在,ViewAssociate是另一个数据库。问题是有权访问Stored Proc的用户没有访问其他数据库的权限,因此我遇到了错误

The server principal "View" is not able to access the database "viewassociate" under the current security context.

所以我只是想知道如何从该表访问另一个数据库表。我可以传递viewassociate数据库的凭据,但是不确定如何更改查询以使用凭据获取数据。有什么建议吗?

谢谢

0 个答案:

没有答案
相关问题