为什么我的视图在SQL Server

时间:2015-09-04 18:38:37

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

我正在尝试将此查询复制到SQL Server中的视图中但我一直收到错误。查询运行正常,但是当我复制并粘贴到视图中时,我在查询的底端出现错误:

  

无效的对象名称'BVSFWarehouse.dbo.sf_OPPORTUNITYHISTORY'

我做错了什么?请帮忙。

SELECT
    H.OpportunityID, H.CREATEDDATE, H.STAGENAME AS 'Q1-14 Stage', 
    H.CLOSEDATE AS 'Q1-14 Close Date'
FROM            
    (SELECT  
         OpportunityID, MAX(CREATEDDATE) AS MaxDate
     FROM            
         BVSFWarehouse.dbo.sf_OPPORTUNITYHISTORY
     WHERE        
         (CREATEDDATE <= '2013-05-01')
     GROUP BY 
         OpportunityID) AS X 
INNER JOIN
    **BVSFWarehouse.dbo.sf_OPPORTUNITYHISTORY** AS H ON H.OpportunityID = X.OpportunityID 
                                                     AND X.MaxDate = H.CREATEDDATE

2 个答案:

答案 0 :(得分:0)

SSMS -> Edit -> IntelliSense -> Refresh Local Cache

Ctrl + Shift + R

再试一次。

答案 1 :(得分:0)

在运行ALTER之前,您没有尝试CREATE视图,是吗?