Since you're using Microsoft SQL Server 2008 R2, another alternative would be to use
the ROW_NUMBER
function[
^]:
WITH cteSortedValues As
(
SELECT
minv_code,
alert_msg,
alert_time,
ROW_NUMBER() OVER (PARTITION BY minv_code ORDER BY alert_time DESC) As RN
FROM
@Table
)
SELECT
minv_code,
alert_msg,
alert_time
FROM
cteSortedValues
WHERE
RN = 1
;
Demo[
^]