• You could also consider using CTEs.

    WITH Notifications AS (

    SELECT sales_order_number

    , count(sales_order_number) as Notification_cnt

    FROM ztb_IMP_Notifications

    GROUP BY sales_order_number)

    SELECT ztb_Carrier_Delivery_Metrics.Delivery

    , ztb_Carrier_Delivery_Metrics.Delivery_Item

    , n.Sales_Order_Number

    , ztb_Carrier_Delivery_Metrics.REF_DOC

    , n.Notification_cnt

    FROM ztb_Carrier_Delivery_Metrics cdm

    INNER JOIN Notifications n ON cdm.REF_DOC = n.Sales_Order_Number

    WHERE cdm.Ref_Doc > ''

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2