sql server - How to delete the duplicate based on date -
I have a table where I have many cust_id duplicate I I would like to keep the line where prendate_next is the closest to the current date And delete all the other duplicates. Please to help me I'm new to this
cust_id prendate_next 1000105737 2014-11-30 00: 00: 00.000 1000105836 2014-11-20 00: 00: 00.000 1000143646 2014-11- 10 00: 00: 00.000 1000143646 2015-03-09 00: 00: 00.000 1000179487 2014-12-05 00: 00: 00.000 1000182253 2015-01-01 00: 00: 00.000 1000192740 2014-10-02 00: 00: 00.000 10001 92740 2015-01-10 00: 00: 00.000 1000199419 20l5-09-30 00: 00: 00.000 1000170578 2014-12-26 00: 00: 00.000 1000188890 20l5-06-23 00: 00: 00.000 1000189075 20l5-03- 01 00: 00: 00.000 1000189075 2015-03-01 00: 00: 00.000 1000189144 2015-04-04 00: 00: 00.000
; Do the (choose as CTA with cust_id, prendate_next, ROW_NUMBER ()) (client by ABS (DATEDIFF (day, prendate_next, divided by GETDATE ())) MyTable on MyLable DELETE Ainer whistle MyTable as Ronland from MyTable) .cust_id = cte.cust_id and MyTable.prendate_next = cte.prendate_next WHERE cte.RowNumber! = 1 ABS (DATEDIFF (DAY, prendate_next, GETDATE))) is How long prendate_next today.
Comments
Post a Comment