当前位置: 代码迷 >> Sql Server >> 帮小弟我看看这个存储过程有什么有关问题
  详细解决方案

帮小弟我看看这个存储过程有什么有关问题

热度:52   发布时间:2016-04-27 19:00:25.0
帮我看看这个存储过程有什么问题?
CREATE   PROCEDURE   [dbo].[spMRViewToProc]  
@FromDbName   varchar(50),
@ToDbName   varchar(50)
AS
exec( 'SELECT   '[email protected]+ '.dbo.materialrequest.*,   ISNULL( '[email protected]+ '.dbo.materialrequestContrast.ModifyDate,  
            '[email protected]+ '.dbo.materialrequest.InputDate)   AS   ModifyDate   INTO   #Temp
FROM   '[email protected]+ '.dbo.materialrequest   LEFT   OUTER   JOIN
            '[email protected]+ '.dbo.materialrequestContrast   ON  
            '[email protected]+ '.dbo.materialrequest.MaterialRequestID   =   '[email protected]+ '.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 '[email protected]+ '.dbo.materialrequest.*, ISNULL( '[email protected]+ '.dbo.materialrequestContrast.ModifyDate,
'[email protected]+ '.dbo.materialrequest.InputDate) AS ModifyDate INTO #Temp
FROM '[email protected]+ '.dbo.materialrequest LEFT OUTER JOIN
'[email protected]+ '.dbo.materialrequestContrast ON
'[email protected]+ '.dbo.materialrequest.MaterialRequestID = '[email protected]+ '.dbo.materialrequestContrast.MaterialRequestID SELECT * FROM #Temp ')

GO
  相关解决方案