Code :
SELECT a.idA, ISNULL(b.PrimaryLanguage,b.SecondaryLanguage) [Text] FROM @Table_A a JOIN ( SELECT idA, max(CASE WHEN idLanguage = 3 THEN Text End) PrimaryLanguage, max(CASE WHEN idLanguage = 2 THEN Text End) SecondaryLanguage FROM @Table_B WHERE idLanguage IN (3,2) GROUP BY idA ) b ON b.idA = a.idA
|