lundi 29 juin 2015

How to INNER JOIN a variable number of tables

I have a table-valued function that returns the members of an AD group:

SELECT GroupName, MemberName FROM dbo.ShowMembers('AD Group Name')

I would like to be able to specify a few AD Group Names and perform an INNER JOIN on each of them to find the common members of all specified AD Group Names.

This works but if I have a number (2-6) of different AD groups to join, it would be easier to add them to a temporary table or variable:

SELECT * FROM dbo.ShowMembers ('Group1') m1, dbo.ShowMembers('Group2') m2
WHERE m1.MemberName = m2.MemberName

Aucun commentaire:

Enregistrer un commentaire