• Scott

    I'm pleased that you found your answer, although I notice that the final query you showed doesn't look much like your original requirement!

    I'd encourage you not to put object names and schema names between inverted commas, for the following reasons:

    (1) It's less readable, and not necessary. If one of your objects contains a space or other unpermitted special character, or shares its name with a keyword (this doesn't apply to anything in your query) then you should use square brackets instead, for the reason below.

    (2) If SET QUOTED_IDENTIFIER is OFF, your query will fail.

    John