• you will probably need to split the IP addresses to deal with the third octet reaching double digits. But with the data you supplied this works:

    SELECT B.Building_Name, D.Device_cnt

    FROM Building_Information AS B

    LEFT JOIN (SELECT LEFT(IP_Address,9) AS Subnet, COUNT(DeviceNum) AS Device_cnt

    FROM Device_Information

    GROUP BY LEFT(IP_Address,9)) AS D

    ON LEFT(B.Subnet,9) = D.Subnet