13

认为我很愚蠢,但我得到了错误:

消息 195,级别 15,状态 1,过程 VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE,第 8 行“分区”不是公认的选项。

尝试执行以下创建视图语句时

CREATE VIEW [dbo].[VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE] 
With partitioned
AS 
(Select 
B.MSH7_DateTimeOfMessage,
B.PID2x1_PatientIDExternal,
B.PID3x1_PatientIDInternal,
B.PID5x1_PatientName_FamilyName,
B.PV3x2_AssignedPatientLocation_Room,
A.OBR4x2_UniversalServiceID_Text,
A.OBX3x2_ObservationIdentifier_Text,
A.OBR24_DiagnosticServiceSectionID,
A.OBR6_RequestDateTime,
C.TestName,
C.PriceBaseline,
D.Contract,
Row_NUMBER()

OVER(Partition By [ORC3_FillerOrderNumber], [OBX3x2_ObservationIdentifier_Text] order by [ORC9_DateTimeOfTransaction]) as seq
From [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_Detail] A
LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_Header] B ON A.[DETAIL_ID] = B.[HEADER_ID]
LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_View_TFCData] C ON A.[OBR24_DiagnosticServiceSectionID] + A.[OBX3x1_ObservationIdentifier_Identifier] = C.[KEY]
LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_LocationDetail] D ON B.[PV3x1_AssignedPatientLocation_PointOfCare] = D.[PracticeCode] 

)
Select *
from partitioned  
where seq =1 

这是一个在存储过程中运行良好的查询,因此我对查询感到满意,只是无法将其创建为视图。

任何帮助将非常感激

4

3 回答 3

19

你错过了AS之后的第一个CREATE VIEW

CREATE VIEW [dbo].[VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE] 
AS --- this is missing
  With partitioned
  AS 
  (
   Select 
      B.MSH7_DateTimeOfMessage,
      B.PID2x1_PatientIDExternal,
      B.PID3x1_PatientIDInternal,
      B.PID5x1_PatientName_FamilyName,
      B.PV3x2_AssignedPatientLocation_Room,
      A.OBR4x2_UniversalServiceID_Text,
      A.OBX3x2_ObservationIdentifier_Text,
      A.OBR24_DiagnosticServiceSectionID,
      A.OBR6_RequestDateTime,
      C.TestName,
      C.PriceBaseline,
      D.Contract,
      Row_NUMBER() OVER(Partition By [ORC3_FillerOrderNumber], [OBX3x2_ObservationIdentifier_Text] order by [ORC9_DateTimeOfTransaction]) as seq
   From [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_Detail] A
   LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_Header] B ON A.[DETAIL_ID] = B.[HEADER_ID]
   LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_View_TFCData] C ON A.[OBR24_DiagnosticServiceSectionID] + A.[OBX3x1_ObservationIdentifier_Identifier] = C.[KEY]
   LEFT OUTER JOIN [NWLHPathApp_DataWarehouse].[dbo].[PathologyHL7_LocationDetail] D ON B.[PV3x1_AssignedPatientLocation_PointOfCare] = D.[PracticeCode] 

   )
   Select *
   from partitioned  
   where seq =1 
于 2013-02-13T11:31:05.503 回答
5

你需要AS之后CREATE VIEW

CREATE VIEW [dbo].[VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE] 
AS
With partitioned ...
于 2013-02-13T11:30:53.843 回答
0

指出您似乎不能在使用 CTE 的同时添加视图列标题可能会有所帮助。(这浪费了我几分钟的时间)

create or replace force editionable view "MYVIEW"
  --("Field1", "Field2")
as 
with results as (
    select cal.field1,cal.field2  from mytable cal
) 
select field1,field2 from results
;

如果您取消注释上面的 ("Field1", "Field2") 列声明,则会失败。

于 2019-01-09T15:54:35.060 回答