HiDECLARE @vcIDs AS VARCHAR(500)-- used VARCHAR because in this way I am able to pass a list of IDsSET @vcIDs ='23,14,07'--SET @vcIDs ='24'-- now will create cte and fill it with individual ID splitted.;WITH cteIDsAS ( SELECT t.u.value('.','INT') AS ids FROM ( SELECT CAST('<ID>'+ REPLACE(@vcIDs,',','</ID><ID>') + '</ID>' AS XML) AS xmlVar) AS X CROSS APPLY X.xmlVar.nodes('ID') t(u) )--SELECT * FROM cteIDs,Countries(ID,Country)AS( SELECT 23, 'USA' UNION ALL SELECT 14, 'Africa' UNION ALL SELECT 15, 'Asia' UNION ALL SELECT 17, 'USA' UNION ALL SELECT 24, 'Asia' UNION ALL SELECT 06, 'Australia' UNION ALL SELECT 07, 'Asia')SELECT CNT.*FROM Countries AS CNT INNER JOIN cteIDs AS I ON CNT.ID=I.ids
output:ID Country23 USA14 Africa7 Asia
sabinWeb MCP