DECLARE
@MissingRows int,
@InsertedRows int
SELECT *
FROM DistributionKey_Section
WHERE SectionID NOT IN ( select siteid from Site where SiteTypeCodeID IN(8) ) AND
DistributionKeyID NOT IN ( SELECT DistributionKeyID FROM DistributionKey WHERE
UnitInclusive=1 )
SET @MissingRows = @@ROWCOUNT
IF @MissingRows > 0
BEGIN
<Insert Statement/Logic>
SET @InsertedRows = @@ROWCOUNT
PRINT CAST(@InsertedRows as varchar(5)) + ' missing rows were detected and added'
IF @MissingRows <> @InsertedRows
BEGIN
RAISERROR('The number of rows inserted does not equal the number of rows missing', 16, 1)
END
END
ELSE
PRINT 'No Missing Rows Detected'