 WITH MC_MaxValueLength AS (
 	SELECT MC.MachineName, MAX(LEN(ISNULL(MC.ConfigValue, ''))) AS MaxLength
 	FROM VCLib.T_MACHINE_CONFIG AS MC
 	GROUP BY MC.MachineName
 ),
 MC_ToKeep AS (
 	SELECT MC.MachineConfigID FROM VCLib.T_MACHINE_CONFIG AS MC
 	JOIN MC_MaxValueLength MCV
 	ON MC.MachineName = MCV.MachineName
 	WHERE LEN(ISNULL(MC.ConfigValue, '')) = MCV.MaxLength
	AND MC.MachineConfigID = (
		SELECT TOP 1 MachineConfigID
		FROM VCLib.T_MACHINE_CONFIG
		WHERE MachineName = MC.MachineName
	)
 )

 DELETE FROM VCLib.T_MACHINE_CONFIG
 WHERE MachineConfigID NOT IN (SELECT MachineConfigID FROM MC_ToKeep) 