SELECT
	ID,
	MeterID,
	ROW_NUMBER() OVER(PARTITION BY MeterID ORDER BY ID) Version
INTO #majorconfig
FROM MeterConfiguration
WHERE DiffID IS NULL

SELECT
	MeterConfiguration.ID,
	MajorConfig.Version MajorVersion,
	ROW_NUMBER() OVER(PARTITION BY MeterID ORDER BY ID) MinorVersion
INTO #fullversion
FROM
	MeterConfiguration CROSS APPLY
	(
		SELECT TOP 1 Version
		FROM #majorconfig
		WHERE
			ID >= MeterConfiguration.ID AND
			MeterID = MeterConfiguration.MeterID
		ORDER BY ID
	) MajorConfig

SELECT DISTINCT *
FROM #fullversion

DROP TABLE #fullversion
DROP TABLE #majorconfig