Click here to Skip to main content
11,715,160 members (62,557 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Anyone with help good people i need a stored procedure that i will use it to return every data in the table after five days or month after stored, so my problem is to count the days then retrieve the data that i want anyone with help
Posted 29-Sep-12 12:45pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

it will return the number of days in the current month
declare @dt datetime
set @dt = getdate()
	DT = @dt,
	[Days in Month] =day(dateadd(mm,datediff(mm,-1,@dt),-1))

or you can try

datediff(day, dateadd(day, 1-day(@date), @date),
              dateadd(month, 1, dateadd(day, 1-day(@date), @date)))
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

For now, steps:
1. Define a date column in your table
2. When you insert any new record, populate the date column value with the DateTime of insertion
3. While retrieving data from DB, use a WHERE clause
4. WHERE clause will be driven by the date column defined. Find the difference in current datetime and the datetime stored. Driving logic would be the difference of the datetime from a given figure (let say 5 days)

Try out.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100