• Here's an alternative using PARSENAME()

    SELECT

    bi.Building_Name,

    COUNT(di.DeviceNum) NumberOfDevices

    FROM #Building_Information bi

    INNER JOIN #Device_Information di

    ON PARSENAME(bi.Subnet,4) = PARSENAME(di.IP_Address,4)

    AND PARSENAME(bi.Subnet,3) = PARSENAME(di.IP_Address,3)

    AND PARSENAME(bi.Subnet,2) = PARSENAME(di.IP_Address,2)

    GROUP BY Building_Name;

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden