Click here to Skip to main content
Rate this: bad
good
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
good
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()
 
select
	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)))
 
  Permalink  
v2
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 460
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2014
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