Solved

sql 2005 query

Posted on 2007-11-25
2
136 Views
Last Modified: 2010-03-19
i have a table with list of data.

i want to get the data from last 5 days using query order by date.
table structure is
itemid
itemname
date
datecreated
username

so i want to get a data based on date for last 5 days
0
Comment
Question by:romeiovasu
2 Comments
 
LVL 35

Accepted Solution

by:
David Todd earned 250 total points
ID: 20347712
Hi,

select
  itemID
  , itemname
  , [date]
  , datecreated
  , username
from dbo.sometable
where [date] > dateadd( dd, -1, getdate() )
order by
  [date]

HTH
  David
0
 
LVL 6

Assisted Solution

by:PaultheBroker
PaultheBroker earned 250 total points
ID: 20347792
where [date] > dateadd(datediff(day,0,getdate()),-5)

otherwise it will be exactly five days ago (120 hours)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now