Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In database i have some 100 records but recently 3 records are inserted in past 1 week.
Then when i run the aspx webform i should get those recently inserted those 3 records.
Can anyone help me
Posted
Comments
ZurdoDev 18-Nov-15 12:32pm    
Sure. What do you need help with? What is your question?
[no name] 18-Nov-15 14:12pm    
Are you looking example sql query ?
Member 11416690 19-Nov-15 5:49am    
yes

You'll need some data in the table to record when the data was inserted and if it was previously "read". When you retrieve the records from the table, you can either retrieve the records from the last date/time that was "read", tracked by your code elsewhere, or you can retrieve records that were "read" before with the flag and just retrieve records that have not been "read". You'll have to have some mechanism in your site to let the user mark thee records "read" so you don't retrieve them again.
 
Share this answer
 
Hi,

If you want to return recently inserted records there should be a date filter, I assume that you are looking recent insert records for past 1week.

Refer below sample query for the same
SQL
Declare @tab table
(
    val int,
	insertdate datetime
)

insert into @tab
values(100,'2015-11-09 12:23:30.377'),(101,'2015-11-10 12:23:30.377'),(102,'2015-11-11 12:23:30.377'),
(104,'2015-11-12 12:23:30.377'),(105,'2015-11-13 12:23:30.377'),(106,'2015-11-14 12:23:30.377'),
(107,'2015-11-15 12:23:30.377'),(108,'2015-11-16 12:23:30.377')

select * from @tab
where CONVERT(date, insertdate) >=CONVERT(date, GETDATE()-7)
 
Share this answer
 
Select *top 3 from your_table orderby ID DESC
This query will fetch last 3 records you have inserted
 
Share this answer
 
Comments
Dave Kreskowiak 18-Nov-15 17:53pm    
And if you don't know how many records were inserted your code falls on its face.
i will go with solution1 and also you can use curent_identity functionality to get most recently entered records in a database
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900