Home All Groups Group Topic Archive Search About


Author
19 Nov 2007 8:08 PM
Paulo
Hi, how can I return from database all the records (DateTime column) from a
range like: mm/yyyy?

Select DateField from Table Where Convert(DateField, 'mm/yyyy', datetime) =
"11/2007" ?

Something like that?

Thanks a lot!

Author
19 Nov 2007 8:25 PM
David Portas
"Paulo" <prbs***@uol.com.br> wrote in message
news:eymI$fuKIHA.5224@TK2MSFTNGP02.phx.gbl...
> Hi, how can I return from database all the records (DateTime column) from
> a range like: mm/yyyy?
>
> Select DateField from Table Where Convert(DateField, 'mm/yyyy', datetime)
> = "11/2007" ?
>
> Something like that?
>
> Thanks a lot!
>

No. Do it like the following, otherwise you'll force the conversion to be
performed for every single row, which is an overhead you don't need.


SELECT DateField
FROM Table
WHERE DateField >= '20071101'
AND DateField < '20071201' ;

--
David Portas
Are all your drivers up to date? click for free checkup

Author
19 Nov 2007 8:30 PM
TheSQLGuru
2 ways I can think of quickly

1) where month(datefield) = 11 and year(datefield) = 2007

2) where datefield between '11/1/2007' and '11/30/2007 23:59:59'


--
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.


Show quoteHide quote
"Paulo" <prbs***@uol.com.br> wrote in message
news:eymI$fuKIHA.5224@TK2MSFTNGP02.phx.gbl...
> Hi, how can I return from database all the records (DateTime column) from
> a range like: mm/yyyy?
>
> Select DateField from Table Where Convert(DateField, 'mm/yyyy', datetime)
> = "11/2007" ?
>
> Something like that?
>
> Thanks a lot!
>
Author
20 Nov 2007 6:55 AM
David Portas
"TheSQLGuru" <kgbo***@earthlink.net> wrote in message
news:13k3siqmsd6tn39@corp.supernews.com...
>2 ways I can think of quickly
>
> 1) where month(datefield) = 11 and year(datefield) = 2007
>
> 2) where datefield between '11/1/2007' and '11/30/2007 23:59:59'
>
>

Don't use option 2. You may exclude some data from the last second of the
day. See my earlier reply.

--
David Portas
Author
20 Nov 2007 9:34 AM
Tibor Karaszi
....and the first will mean indexes cannot be used to improve performance of the query. My take on
the subject: http://www.karaszi.com/SQLServer/info_datetime.asp

Show quoteHide quote
"David Portas" <REMOVE_BEFORE_REPLYING_dpor***@acm.org> wrote in message
news:%23jKBJJ0KIHA.5920@TK2MSFTNGP03.phx.gbl...
> "TheSQLGuru" <kgbo***@earthlink.net> wrote in message news:13k3siqmsd6tn39@corp.supernews.com...
>>2 ways I can think of quickly
>>
>> 1) where month(datefield) = 11 and year(datefield) = 2007
>>
>> 2) where datefield between '11/1/2007' and '11/30/2007 23:59:59'
>>
>>
>
> Don't use option 2. You may exclude some data from the last second of the day. See my earlier
> reply.
>
> --
> David Portas
>
>

Bookmark and Share