1

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

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

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
4

1 回答 1

1

看看如何使用 sp_refreshview 确保视图将具有基础表更改

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

于 2010-06-03T20:14:08.617 回答