?
Solved

query to extract records in a range of dates

Posted on 2007-07-25
7
Medium Priority
?
426 Views
Last Modified: 2008-01-09
HI, I would need a query that extract all the records between a given date and today's date.

I need a query that could work without *any issues* on any sql 2000 / 2005 dbs, indipendenly on what are the language settings of sql/server

Thanks and regards
0
Comment
Question by:NetDeveloper
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 19564159
SELECT * FROM urTable WHERE urDateColumn >= @StartDAte  AND urDateColumn < CONVERT(varchar,getdate(),112)
0
 
LVL 10

Author Comment

by:NetDeveloper
ID: 19564225
Yes, it is ok aneeshattingal I tested it :)
The points are yours. I would ask you fust another thing:

The @StartDAte I have to test is the 22 of june 2007
Could you please update ur query where @StartDAte is the 22 of june 2007

Thanks and best regards

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1000 total points
ID: 19564250
WHERE urDateColumn >= '2007-07-22'
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 19564261
oops, 22nd june 2007 should be  '2007-06-22'
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 19564269
or like this

declare @StartDate datetime
SELECT @StartDate = '27-june-2007'
SELECT * FROM urTable WHERE urDateColumn >= @StartDAte  AND urDateColumn < CONVERT(varchar,getdate(),112)


the bove Query wont return any records of today, if you need to get todays records also, then

SELECT * FROM urTable WHERE urDateColumn >= @StartDAte  AND urDateColumn < CONVERT(varchar,getdate()+1,112)

0
 
LVL 10

Author Comment

by:NetDeveloper
ID: 19564631
Hi, I get the error:

the conversion from char to datetime generated a datetime value out of range
0
 
LVL 10

Author Comment

by:NetDeveloper
ID: 19564659
It is ok...Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

864 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