Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to write a query/stored procedure where I want to get a specific number for records (say 10) from the database according to the time they are inserted into DB.

I store the insert time using SYSDATE and I want to retrieve the first ten inserted records (i.e. having smallest SYSDATE value) and then delete those from DB in one transaction.

If my table looks something like this:

RecordNum

RecordType

InsertTime

10

A

10/08/2007 14:20

20

B

10/08/2007 14:22

 

 

10/08/2007 14:27

 

Please let me know how to go about it.

Thanks,

Anup

Posted

TOP keyword

 

I assume this is a SQL Server database. In this case one approach is to use the TOP keyword:

 

SELECT TOP 10 RecordNum, RecordType, InsertTime FROM MyTable ORDER BY InsertTime ASC

 

Other database engines use different keywords, such as LIMIT in MySql.

 

Good luck :cool:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...