Solved

returning all records entered in a week

Posted on 1997-11-17
2
250 Views
Last Modified: 2012-08-13
I have two problems with SQL

problem 1

I'm using LiveWire Pro to connect to a DB in MS-SQL.  I need to return all records entered in the last week or the last 10 days or 2 weeks etc. etc.

problem 2

I can entered carriage returns in my textbox which are stored in the DB.  Whenever I retrieve the data from the DB, CR's are stripped out.  I'm not putting the data from the DB back into a textbox - just into a formatted table
0
Comment
Question by:bode
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
bret earned 100 total points
ID: 1089131
1)  

declare @days_back
select @days_back = -7
Select * from table
where enter_date > dateadd(day,-7,getdate()).

The sql above will get you all records
entered in the last 7 days.  If you run this at 2:22 pm
on Monday, Nov 17th, you will get everything entered since
2:22 pm Monday, Nov 10th.  If you want everything from the
midnight preceeding Nov 10th, you need to strip the time information from the datetime [note that any date will
work as the initial @referencedate, it is completely arbitrary]:

declare @referencedate datetime
select @referencedate = "1/1/1950"
select @referencedate = dateadd(day,datediff(day,@referencedate,getdate()),@referencedate)
select * from mytable
where insert_date > dateadd('day',-7,@referencedate)

2)  Don't know.  (These are two completely unrelated questions.
You really should open them as seperate questions (at half the points each, perhaps))
0
 

Author Comment

by:bode
ID: 1089132
Thanks Bret

I've actually already solved the problem!  I used the following:

SELECT * FROM mytable WHERE DATEDIFF(DD, mydatefield, GETDATE()) BETWEEN 0 AND 7

This selects all records entered in the last 7 days
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

617 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