HiI'm assuming that you want all articles associated with each machine as contiguous columns with any NULL values appearing at the end. As such, you need an ordinal position to use when 'unfolding' this data. I've added this to a derived table, but this would probably be done in a view or added to your underlying table.You could get away without this if your columns represented specific articles, in which case you would replace "CASE WHEN acc.ORDINAL_POS = ..." with "CASE WHEN acc.ARTICLE_OBJ_NO = ..."SELECT MACHINE_NO, MAX(CASE WHEN acc.ORDINAL_POS = 1 THEN art.ARTICLE_DESCRIPTION ELSE NULL END) AS '1', MAX(CASE WHEN acc.ORDINAL_POS = 2 THEN art.ARTICLE_DESCRIPTION ELSE NULL END) AS '2', MAX(CASE WHEN acc.ORDINAL_POS = 3 THEN art.ARTICLE_DESCRIPTION ELSE NULL END) AS '3', MAX(CASE WHEN acc.ORDINAL_POS = 4 THEN art.ARTICLE_DESCRIPTION ELSE NULL END) AS '4'/*, etc.*/FROM( SELECT acc.MACHINE_OBJ_NO, acc.ACC_NO, acc.ARTICLE_OBJ_NO, ( SELECT COUNT(*) + 1 FROM ACCESSORIES AS acc2 WHERE acc2.MACHINE_OBJ_NO = acc.MACHINE_OBJ_NO and acc2.ARTICLE_OBJ_NO < acc.ARTICLE_OBJ_NO ) AS ORDINAL_POS FROM ACCESSORIES AS acc) AS acc JOIN dbo.MACHINE AS m ON acc.MACHINE_OBJ_NO = m.OBJ_NO JOIN dbo.ARTICLE AS art ON acc.ARTICLE_OBJ_NO = art.OBJ_NOGROUP BY m.MACHINE_NOORDER BY m.MACHINE_NO
Mark