tags:

views:

42

answers:

3

I have an sql server view which I've recently added a field to the underlying table and the view itself. I can open the view just fine on the server, but when I try to run it in SQL management Studio on my PC, I get the following error:

>     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'.

Code is not the column that was added, in fact the added column isn't even on that table.

And Here is the view:

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

How can I correct this so the error does not happen?

+2  A: 

Try sp_refreshview

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

Use SCHEMABINDING if possible too

gbn
sp_refreshview had no effect. What did you mean by SchemaBinding?
MAW74656
A: 

The problem seems to have worked itself out. I don't know how or why. Thanks guys!

MAW74656
DB objects are precompiled. They are usually smart enough to recompile the first time you use them after changing the db objects they depend on. In the bad old days, we use to ALTER VIEW or ALTER PROCEDURE and add whitespace to force a recompile. Problem probably went away when some cleanup process finally got around to forcing the recompile.
Bill
I actually saw the problem again with users in a particular role. I altered the view by adding whitespace and then the errors went away for them too. Bizarre.
MAW74656