I am looking for something like this but can\'t figure out the best way to write the query:
SELECT DISTINCT CategoryID FROM tbl_Categories c INNER JOIN
ma
Not sure if it's really that what you want as your question is a bit unclear.
DECLARE @SQL NVARCHAR(MAX)
DECLARE @IDs NVARCHAR(MAX)
SET @IDs = '234,245,645'
SET @SQL = 'SELECT DISTINCT CategoryID FROM tbl_Categories c INNER JOIN
mappingTable mp ON c.CategoryID = mp.CategoryID INNER JOIN
SubCategories sc ON mp.SubCategoryID = sc.SubCategoryID
WHERE sc.SubcategoryID IN (' + @IDs + ')'
exec (@sql)