You want to only run if none of these exist.
You could use the EXISTS keyword.
Something like this.
IF NOT EXISTS SELECT ID FROM Master1 WHERE (...)
IF NOT EXISTS SELECT ID FROM Master2 WHERE (...)
IF NOT EXISTS SELECT ID FROM Master3 WHERE (...)
BEGIN
..do stuff...
END
Note that I don't use count, if count is zero NOT EXISTS is true. Select any column to get the query to run.
Can't test right now, the syntax might look like this:
IF NOT EXISTS (SELECT ID FROM Master1 WHERE (...))
IF NOT EXISTS (SELECT ID FROM Master2 WHERE (...))
IF NOT EXISTS (SELECT ID FROM Master3 WHERE (...))
BEGIN
..do stuff...
END