Delting duplicate rows with condition

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT 326.8 AS ITEMCHARGE , 29075 AS CPT4 , 20101204 AS EFF_DATE , 'GO' AS CPT4MOD
INTO #Table
UNION ALL
SELECT 326.8 , 29075 , 20110104 , 'GO'
UNION ALL										
SELECT 326.8 , 29075 , 20110204 , 'GO'
UNION ALL										
SELECT 326.8 , 29075 , 20110406 , 'GO'
UNION ALL										
SELECT 352.69 , 29075 , 20090611 , 'GO'
UNION ALL										
SELECT 352.69 , 29075 , 20090917 , 'GO'
UNION ALL										
SELECT 352.69 , 29075 , 20100614 , 'GO'
UNION ALL										
SELECT 352.69 , 29075 , 20100722 , 'GO'

SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY CPT4, CPT4MOD, ITEMCHARGE ORDER BY EFF_DATE DESC) AS RowNo
	, *
FROM #table
) AS T
WHERE T.RowNo = 1

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results