2

This issue was resolved by scripting the view as a create, dropping the view, and then recreating the view using the script, so obviously nothing was wrong with the view, per se. However, I am very curious as to what the cause could be...

I have a created like this:

CREATE VIEW [dbo].[Employees_V]
AS
SELECT  cast(right(EmployeeNo,4) as int) as EmployeeID
,*
,cast(0 as bit) AS [IsTerritoryManager]
,cast(0 as bit) AS [IsCoordinator]
FROM    AD.dbo.ADEmployees_V

The AD.dbo.ADEmployees_V has a lot of different fields, but the relevant fields are Status and ISStatus, defined in the creation of the view as:

,CASE WHEN c.[Status] = 'Active' THEN 'Active' ELSE 'Terminated' END AS [Status]
,CASE WHEN c.[Status] = 'Active' OR ad.[AccountStatus] LIKE '%Enabled%' THEN 'Active' ELSE 'Terminated' END AS [ISStatus]

Today, I added the ISStatus column to AD.dbo.ADEmployees_V (Status was there previously).

After making that change, I did a:

SELECT * FROM [Employees_V]

Surprisingly, this did not return the proper results. ISStatus did not appear as a column header, and instead of being populated with 0s, IsTerritoryManager was populated with the new ISStatus values!

I am guessing that this is some sort of caching issue, but I would love an explanation of what is going on under the covers. Thanks!

4

1 回答 1

1

视图的列列表是在 CREATE 或 ALTER 时生成的。如果您SELECT * FROm table在视图定义中使用 a ,则视图的列列表将填充table的当前字段列表。

向表中添加新列不会更改视图定义,这就是为什么您需要重新创建它以“刷新”它的列。

于 2012-11-02T08:20:40.497 回答