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と、ビューの列リストにtableの現在のフィールド リストが入力されます。

テーブルに新しい列を追加しても、ビューの定義は変更されません。そのため、列を「更新」するには、ビューを再作成する必要があります。

于 2012-11-02T08:20:40.497 に答える