帮我看看这个存储过程有什么问题?
CREATE PROCEDURE [dbo].[spMRViewToProc]
@FromDbName varchar(50),
@ToDbName varchar(50)
AS
exec( 'SELECT '+@FromDbName+ '.dbo.materialrequest.*, ISNULL( '+@ToDbName+ '.dbo.materialrequestContrast.ModifyDate,
'+@FromDbName+ '.dbo.materialrequest.InputDate) AS ModifyDate INTO #Temp
FROM '+@FromDbName+ '.dbo.materialrequest LEFT OUTER JOIN
'+@ToDbName+ '.dbo.materialrequestContrast ON
'+@FromDbName+ '.dbo.materialrequest.MaterialRequestID = '+@ToDbName+ '.dbo.materialrequestContrast.MaterialRequestID ')
SELECT * FROM #Temp
GO
(所影响的行数为 24 行)
报错:服务器: 消息 208,级别 16,状态 1,过程 spMRViewToProc,行 10
对象名 '#Temp ' 无效。
请问:这个怎么改??
------解决方案--------------------CREATE PROCEDURE [dbo].[spMRViewToProc]
@FromDbName varchar(50),
@ToDbName varchar(50)
AS
exec( 'SELECT '+@FromDbName+ '.dbo.materialrequest.*, ISNULL( '+@ToDbName+ '.dbo.materialrequestContrast.ModifyDate,
'+@FromDbName+ '.dbo.materialrequest.InputDate) AS ModifyDate INTO #Temp
FROM '+@FromDbName+ '.dbo.materialrequest LEFT OUTER JOIN
'+@ToDbName+ '.dbo.materialrequestContrast ON
'+@FromDbName+ '.dbo.materialrequest.MaterialRequestID = '+@ToDbName+ '.dbo.materialrequestContrast.MaterialRequestID SELECT * FROM #Temp ')
GO