更改视图无法识别列

时间:2010-06-03 20:10:32

标签: tsql sql-server-2008-r2

我有用于向表格添加列的脚本。

当我运行脚本以使用新列更改视图时,脚本会因为无法识别列而失败

Msg 207, Level 16, State 1, Procedure UniqueTempDispositions, Line 76
Invalid column name 'servicerequestid'.
Msg 207, Level 16, State 1, Procedure UniqueTempDispositions, Line 47
Invalid column name 'servicerequestid'.
Msg 207, Level 16, State 1, Procedure MergeDispositions, Line 54
Invalid column name 'ServiceRequestID'.
Msg 207, Level 16, State 1, Procedure NonPIICachedDispositions, Line 18
Invalid column name 'ServiceRequestID'.

有什么理由?我错过了什么吗?

我已经启动并停止了服务器,我已经重新开始无济于事了。 原文:

alter view 
dbo.UniqueTempDispositions 
as 
SELECT     QuotaGroup, Country, ServiceGroup, Language, ContactChannel, TrackingID, CONVERT(DATETIME, CaseClosedDate) AS casecloseddate, MSFTRep, CustEmail,  
                      CustPhone, CustomerName, ProductFamily, ProductSubType, CONVERT(DATETIME, CandidateReceivedDate) AS candidatereceiveddate, CONVERT(INT, SurveyMode)  
                      AS surveymode, CONVERT(DATETIME, SurveyWaveStartDate) AS surveywavestartdate, CONVERT(DATETIME, SurveyInvitationDate) AS surveyinvitationdate,  
                      CONVERT(DATETIME, SurveyReminderDate) AS surveyreminderdate, CONVERT(DATETIME, SurveyCompleteDate) AS surveycompletedate, CONVERT(DATETIME,  
                      OptOutDate) AS optoutdate, CONVERT(DATETIME, SurveyWaveEndDate) AS surveywaveenddate, CONVERT(INT, DispositionCode) AS dispositioncode, SurveyName,  
                      SurveyVendor, COUNT(*) AS countofunique, BusinessUnitName, UploadId, MIN(LineNumber) AS LineNumber, BusinessUnitSubgroup, ServiceRequestID 
FROM         DispositionReporting.dbo.tempDispositions AS td 
GROUP BY QuotaGroup, Country, ServiceGroup, Language, ContactChannel, TrackingID, CONVERT(DATETIME, CaseClosedDate), MSFTRep, CustEmail, CustPhone,  
                      CustomerName, ProductFamily, ProductSubType, CONVERT(DATETIME, CandidateReceivedDate), CONVERT(INT, SurveyMode), CONVERT(DATETIME,  
                      SurveyWaveStartDate), CONVERT(DATETIME, SurveyInvitationDate), CONVERT(DATETIME, SurveyReminderDate), CONVERT(DATETIME, SurveyCompleteDate),  
                      CONVERT(DATETIME, OptOutDate), CONVERT(DATETIME, SurveyWaveEndDate), CONVERT(INT, DispositionCode), SurveyName, SurveyVendor, BusinessUnitName,  
                      UploadId, BusinessUnitSubgroup, ServiceRequestID 
go 

我最终放弃并重新添加了有效的视图,只是不明白其他方式:

use DispositionReporting
go
drop view dbo.UniqueTempDispositions
go
create view
dbo.UniqueTempDispositions
as
SELECT     QuotaGroup, Country, ServiceGroup, Language, ContactChannel, TrackingID, CONVERT(DATETIME, CaseClosedDate) AS casecloseddate, MSFTRep, CustEmail, 
                      CustPhone, CustomerName, ProductFamily, ProductSubType, CONVERT(DATETIME, CandidateReceivedDate) AS candidatereceiveddate, CONVERT(INT, SurveyMode) 
                      AS surveymode, CONVERT(DATETIME, SurveyWaveStartDate) AS surveywavestartdate, CONVERT(DATETIME, SurveyInvitationDate) AS surveyinvitationdate, 
                      CONVERT(DATETIME, SurveyReminderDate) AS surveyreminderdate, CONVERT(DATETIME, SurveyCompleteDate) AS surveycompletedate, CONVERT(DATETIME, 
                      OptOutDate) AS optoutdate, CONVERT(DATETIME, SurveyWaveEndDate) AS surveywaveenddate, CONVERT(INT, DispositionCode) AS dispositioncode, SurveyName, 
                      SurveyVendor, COUNT(*) AS countofunique, BusinessUnitName, UploadId, MIN(LineNumber) AS LineNumber, BusinessUnitSubgroup, ServiceRequestID
FROM         DispositionReporting.dbo.tempDispositions AS td
GROUP BY QuotaGroup, Country, ServiceGroup, Language, ContactChannel, TrackingID, CONVERT(DATETIME, CaseClosedDate), MSFTRep, CustEmail, CustPhone, 
                      CustomerName, ProductFamily, ProductSubType, CONVERT(DATETIME, CandidateReceivedDate), CONVERT(INT, SurveyMode), CONVERT(DATETIME, 
                      SurveyWaveStartDate), CONVERT(DATETIME, SurveyInvitationDate), CONVERT(DATETIME, SurveyReminderDate), CONVERT(DATETIME, SurveyCompleteDate), 
                      CONVERT(DATETIME, OptOutDate), CONVERT(DATETIME, SurveyWaveEndDate), CONVERT(INT, DispositionCode), SurveyName, SurveyVendor, BusinessUnitName, 
                      UploadId, BusinessUnitSubgroup, ServiceRequestID
go
exec sp_refreshview 'dbo.UniqueTempDispositions'
go

1 个答案:

答案 0 :(得分:1)

查看how to make sure that the view will have the underlying table changes by using sp_refreshview

在对表进行更改后,是否针对视图运行了sp_refreshview?

相关问题