USE SwissIndex_Products_Work GO DECLARE @t TABLE (ItemType VARCHAR(100), IndexCode INT, Dt DATETIME, INDEX IxDt (Dt)) INSERT INTO @t (ItemType, IndexCode, Dt) SELECT ItemType, IndexCode, Dt FROM ( SELECT ItemType, 128 AS IndexCode, MIN(Db_InsDT) AS Dt FROM dbo.QuarantineItems WHERE NOT ItemType = 'ARTICLE' GROUP BY ItemType UNION ALL SELECT ItemType, IndexCode, MIN(Db_InsDT) AS Dt FROM dbo.QuarantineItems WHERE ItemType = 'ARTICLE' GROUP BY ItemType, IndexCode ) g SELECT * FROM @t ORDER BY Dt