sql – 使用CTE创建视图时出错

认为我是愚蠢但我得到错误

Msg 195,Level 15,State 1,Procedure
VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE,Line 8 ‘partitioned’
is not a recognized option.

尝试执行以下create view语句时

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

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

任何帮助将非常感激

解决方法

您错过了 CREATE VIEW之后的第一个AS:
CREATE VIEW [dbo].[VW_THIRDPARTY_SLA_REPORT_MONTHLY_GP_NONAGGREGATE] 
AS --- this is missing
  With partitioned
  AS 
  (
   Select 
      B.MSH7_DateTimeOfMessage,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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...