Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to select data from today to last 5 days from the sql server 2005.
example:
tblPaymentDetail(Table Name)

Fields Are:
appPaymentDate
appAmount


In my table records are inserted like this:

appPaymentDate appAmount

18-07-2012 100
16-07-2012 200
18-07-2012 300
15-07-2012 740


I want last 5 days record with sum of appAmount .

Result:
Assume todays date is 20-07-2012

I want
19-07-2012 0
18-07-2012 400
17-07-2012 0
16-07-2012 200
15-07-2012 740

please help me.

Thank you in advance.
Posted
Updated 31-Aug-20 7:12am
v4

Try:
SQL
SELECT * FROM tblPaymentDetail WHERE appPaymentDate >= DATEADD(day, -5, GetDate())
 
Share this answer
 
SQL
select * from table where   day(appPaymentDate )   between   (day(getdate())-5)   and   (day(getdate()))
 
Share this answer
 
select * from tablename where coloumn >=sysdate-5
 
Share this answer
 
Comments
CHill60 1-Sep-20 6:11am    
This 8 year old question clearly states SQL Server. Not Oracle. Not MySql.
There is no SysDate in SQL Server, it is GetDate

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