I am trying to get all the duplicated records based on :
accession_id,
check_num,
procedure_code,
paid_amt,
this query will return the above along with the number of times those fields were repeated.
however, i want to only return those that occur more than once.
select
ACCESSION_PAYMENTS_DAILY_KEY,
accession_id,
check_num,
procedure_code,
paid_amt,
row_number()
over
(partition by accession_id, check_num,procedure_code,paid_amt order by ACCESSION_PAYMENTS_DAILY_KEY) as occurrence
from [MILLENNIUM_DW_DEV].[dbo].[F_PAYOR_PAYMENTS_DAILY]
where PROCEDURE_CODE is not null
and PAID_AMT>0
when i add the filter condition occurrence>1 to the above query, i am getting this error:
Msg 207, Level 16, State 1, Line 13
Invalid column name 'occurrence'.
how can i return the records only if they occur more than once?
If you want to use an alias in a
WHEREclause then you can wrap it in anotherSELECTstatement.