Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Records using a part of a date 1

Status
Not open for further replies.

da644

Programmer
May 21, 2001
159
GB
Hi Everyone.

I have a table with a date field and I would like to extract all records with a date with a certain month or year. One way I thought of doing this was:

select fieldnames
from tablename
where datefield >= '2003/10/01'
and datefield <= '2003/10/31'

and something similar for the year, however this for some reason seems very inefficient (maybe its not), but is there a better way?

Thanks

Best Regards

Andrew.
 
it is actually very efficient

it allows an index on the datefield to be used

you do have an index, right?


rudy
 
Hi

Yeah, I did think of it like that. It just didn't look good when I coded it.

Thanks

Best Regards

Andrew.
 
if you dont like typing you can use :
select fieldnames
from tablename
where datefield like '2003/10/__'


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The doesn't seem to work. is the __ part two underscores?
 
yes , each _ (underscore) represents a single character, for multiple characters use % or the correct number of _.




______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top