query to extract records in a range of dates

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
LVL 10
NetDeveloperAsked:
Who is Participating?
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
WHERE urDateColumn >= '2007-07-22'
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT * FROM urTable WHERE urDateColumn >= @StartDAte  AND urDateColumn < CONVERT(varchar,getdate(),112)
0
 
NetDeveloperAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Aneesh RetnakaranDatabase AdministratorCommented:
oops, 22nd june 2007 should be  '2007-06-22'
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
 
NetDeveloperAuthor Commented:
Hi, I get the error:

the conversion from char to datetime generated a datetime value out of range
0
 
NetDeveloperAuthor Commented:
It is ok...Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.