SELECT 
    o.[HN], 
    o.[FULLNAME] AS Name, 
    o.[REQ ITEM NAME] AS Test
FROM view_lab_statistic_Order_List AS o
JOIN tbl_lab_setup_Test_Control AS c ON o.[REQ ITEM CODE] = c.Test_Code
WHERE 
    o.[order inactive] <> 'Y' 
    AND o.[req item state] <> 'R' 
    AND c.Test_Limit_Order_Flag = 1
    AND o.[REQ ITEM ORDER DATETIME] BETWEEN '@d1' AND '@d2'
    AND EXISTS (
        SELECT 1 
        FROM view_lab_statistic_Order_List AS so
        WHERE so.HN = o.HN 
          AND so.[REQ ITEM CODE] = o.[REQ ITEM CODE]
          AND so.LN <> o.LN
          AND so.[order inactive] <> 'Y'
          AND so.[ORDER DATETIME] > DATEADD(DAY, ISNULL(c.Test_Limit_Order_Day, 0) * -1, o.[ORDER DATETIME])
    )

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: