1
SELECT 
    ISNULL(LAB_ORD.Accession_No, '') AS [Accession Number],
    MPI.Medical_Record_Number AS [MRN],
    RIGHT(('0000'+ CONVERT(VARCHAR(50), EP.Episode_No)), 4) AS [Episode Number],
    ISNULL(EP.Patient_Name, '') AS [Patient Name],
    ISNULL(PEO.Birth_Sex, '') AS [Sex], 
    CAST(PEO.DOB AS varchar) AS [DOB],    
    ISNULL(PEO.Address1, '') AS [Address 1],
    ISNULL(PEO.Address2, '') AS [Address 2],
    ISNULL(PEO.City, '') AS [City],     
    ISNULL(PEO.State_Code, '') AS [State], 
    ISNULL(PEO.Zip, '') AS [Zip Code], 
    ISNULL(PEO.Home_Phone, '') AS [Home Phone],
    ISNULL(PEO.Work_Phone, '') AS [Work Phone],
    ISNULL(PEO.Other_Phone, '') as [Cell Phone],
    ISNULL(PEO.Email, '') as [Email],
    ISNULL(STAFF.Staff_Name, ISNULL(PPL3.Person_Name, '')) AS [Ordering Provider], 
    CAST(LAB_ORD.Collection_Date AS varchar) AS [Collection Date],
    ISNULL(SPC.Description, '') AS Description,  ---Patient Class   Description,
    ISNULL(LAB_ORD.Location, '') AS [Order Location],
    ISNULL(LAB_ORD.Order_Status, '') [Order Status],
    ISNULL(LT.Test_Code, '') AS [Test Code],
    ISNULL(LT.Report_Name, '') AS [Report Name],
    ISNULL(LR.Result, '') AS [Result],
    ISNULL(cast(LR.Result_DT as varchar), '') AS [Result Date & Time],
    ISNULL(CAST(LAB_ORD.Final_Date AS varchar), '')[Final Date] 
FROM
    LIS_Orders AS LAB_ORD  
LEFT JOIN 
    LIS_Order_Tests AS OT ON LAB_ORD.OrderID = OT.OrderID      
LEFT JOIN 
    LIS_Facilities AS FAC ON LAB_ORD.FacilityID = FAC.FacilityID      
LEFT JOIN 
    shr_Episodes AS EP ON LAB_ORD.EpisodeID = EP.EpisodeID      
LEFT JOIN 
    shr_Patient_Classes AS SPC  ON EP.Patient_ClassID = SPC.Patient_ClassID      
LEFT JOIN 
    shr_MPI AS MPI  ON EP.MPIID = MPI.MPIID      
LEFT JOIN 
    glb_People AS PEO  ON MPI.Peopleid = PEO.PeopleID          
LEFT JOIN 
    LIS_Results AS LR  ON LR.Order_TestID = OT.Order_TestID           
LEFT JOIN 
    LIS_Tests AS LT  ON LT.TestID = LR.TestID 
LEFT JOIN 
    shr_Staffs AS STAFF  ON STAFF.StaffID = LAB_ORD.Ordering_PhysicianID   
LEFT JOIN 
    glb_People AS PPL3  ON PPL3.PeopleID  = STAFF.PersonId
WHERE 
    Test_Code = '139901'
    OR (Test_Code LIKE '164073')
    OR (Test_Code LIKE '%sars%')
    OR (Test_Code LIKE '%covid%')
    AND LAB_ORD.Order_Status IN ('F', 'C')
    AND (Result NOT LIKE '.')

我需要代码只显示 LAB_ORD.Order_Status 中的 F 和 C 不幸的是,代码无法识别此命令并显示 F、C、X、P

4

1 回答 1

2

当您使用 OR 和 AND 时,使用 parentesis 来说明它们必须被评估的顺序总是一个好主意。在您的情况下, Where 子句可能应该这样写:

WHERE 
(
   Test_Code='139901'
   or (Test_Code like '164073')
   or (Test_Code like '%sars%')
   or (Test_Code like '%covid%')
)
and LAB_ORD.Order_Status IN ('F','C')
and (Result not like '.')
于 2021-09-18T00:13:05.453 回答