我有一个应该在DB1上运行的SP(使用DB1),使用此DB1中的一些表并将其与DB2表组合。
如果我在DB1上运行此SP,则会收到一个错误,但是如果我更改与DB2的连接,它将很好地工作。 问题是不允许我在此DB2上创建SP。
当然,我在查询中有一个数据库前缀。
答案 0 :(得分:0)
CREATE PROCEDURE CheckForShipment
AS
BEGIN
Create DB1.TempTable
(a,b,c,d)
insert into DB1.TempTable
select a,b,c,d
from DB1.ShipmentData as aa
left join
(select e,f,g,h
from DB2.SysTable
) as bb on aa.a = bb.e
-------------
declare
@b nvarchar(max),
@c nvarchar(max),
@Sc nvarchar(max),
@Me nvarchar(max);
Declare ListOfShipments
For
Select b,c,d from DB1.TempTable
Open ListOfShipments
FETCH NEXT FROM ListOfShipments INTO @b,@b,@d
WHILE @@FETCH_STATUS = 0
BEGIN
exec (@Sc)
SET @Me = something
FETCH NEXT FROM ListOfShipments
END
CLOSE ListOfShipments
DEALLOCATE ListOfShipments
-----------------
---SEND EMAIL
EXEC msdb.dbo.sp_send_dbmail
@profile_name = etc.
enter code here
Drop table DB1.TempTable
End