打开视图时出现SQL错误

时间:2010-10-22 19:52:31

标签: sql sql-server

我有一个sql server视图,我最近在底层表和视图本身中添加了一个字段。我可以在服务器上打开视图,但是当我尝试在我的PC上的SQL管理工作室中运行它时,我收到以下错误:

>     Msg 7352, Level 16, State 1, Line 2
>     OLE DB provider 'SQLOLEDB' supplied inconsistent metadata. The
> object
> '[AVANTISERVER\NCL_MASTER].[Avanti].[dbo].[EmployeeFile]'
> was missing expected column 'Code'.

代码不是添加的列,实际上添加的列甚至不在该表上。

以下是观点:

ALTER  VIEW [dbo].[WorkOrdersDetailed]
AS
   SELECT m.Serial, 
          m.Description, 
          m.Make, 
          m.Model, 
          m.Notes, 
          wo.WorkOrderID, 
          wo.DueDate, 
          dbo.DateOnly(wo.DueDate) AS [Due Date], 
          ISNULL(wo.AssignedTo, '') AS AssignedTo, 
          wo.WorkTypeID, 
          wo.Completed, 
          wo.DateCompleted, 
          wo.CompletedBy, 
          wo.Manager, 
          wo.FollowUpBy, 
          wo.FollowUpDate, 
          wt.Category, 
          wt.Description AS WorkType, 
          REPLACE(wt.Notes, '\r\n', '<br />') AS WorkTypeNotes, 
          wt.Duration, 
          CASE wt.Frequency 
            WHEN '0' THEN 'None' 
            WHEN '1' THEN 'Daily' 
            WHEN '7' THEN 'Weekly' 
            WHEN '28' THEN 'Monthly' 
            WHEN '56' THEN 'Bi-Monthly' 
            WHEN '84' THEN 'Quarterly' 
            WHEN '168' THEN 'Semi-Annually' 
            WHEN '365' THEN 'Annually' 
            ELSE 'None' 
          END AS Frequency, 
          wo.CompletionNotes, 
          wo.CreatedBy, 
          wo.DateCreated, 
          wt.Status, 
          CASE Priority 
            WHEN '1' THEN '1-Highest' 
            WHEN '2' THEN '2-High' 
            WHEN '3' THEN '3-Normal' 
            WHEN '4' THEN '4-Below Normal' 
            WHEN '5' THEN '5-Lowest'
            ELSE 'None' 
          END AS Priority, 
          CASE dbo.Departments.DepartmentName 
            WHEN 'Information Technology' THEN 'I.T.' 
            ELSE dbo.Departments.DepartmentName + ' - ' + dbo.CostCenter.CenterName
          END AS Location, 
          wo.ToolsReconciled, 
          wo.PartsReconciled, 
          wo.CleanReconciled, 
          wo.TurnedOverTo + ' - ' + dbo.AvantiEmployeeData.LongName AS TurnedOverTo, 
          wo.TempRepair
     FROM dbo.WorkType  wt
     JOIN dbo.WorkOrders wo ON wo.worktypeid = wo.worktypeid
     JOIN dbo.Machines m ON m.serial = wo.machineserial
     JOIN dbo.CostCenter cc ON cc.costcenterid = m.costcenter
LEFT JOIN dbo.Departments d ON d.departmentid = cc.department
LEFT JOIN dbo.AvantiEmployeeData aed ON aed.code = wo.turnedoverto

如何更正此错误,以免发生错误?

2 个答案:

答案 0 :(得分:2)

尝试使用sp_refreshview

http://msdn.microsoft.com/en-us/library/ms187821.aspx

如果可能,请使用SCHEMABINDING

答案 1 :(得分:0)

显然这是一个已知问题。创建一个视图,然后查询视图。见链接:

http://support.microsoft.com/kb/255097