Thursday, October 11, 2012

How to Get Last updated /Inserted records from the table in sql server

How could you solve if you had a big problem with data base when insert the huge amount of duplicate records into table ?The same situation i have faced recently.by the time i  simply makes the insertion process for that bulk records.But later on i got a trouble  with those records .For this i want to checked out to display the recent insertion data from table.In the  below query i have used date function and length function to get the last updated records which are  greater than current date minus 5 (last five days) and length of header is greater than 4
select * from order
where len(order_head)<=4
and (inactive_date is not mull or inactive_date > getdate()-5)
and order_head is not null
and order_code like 'SAT%'
Finally all redundant insertion records has been deleted for last five days using the below query
Delete order
where len(order_head)<=4
and (inactive_date is not mull or inactive_date > getdate()-5)

No comments:

Bel