|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Date Sql 2000
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! "Paulo" <prbs***@uol.com.br> wrote in message No. Do it like the following, otherwise you'll force the conversion to be 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! > 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 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' -- Show quoteHide quoteKevin G. Boles TheSQLGuru Indicium Resources, Inc. "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! > "TheSQLGuru" <kgbo***@earthlink.net> wrote in message Don't use option 2. You may exclude some data from the last second of the 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' > > day. See my earlier reply. -- David Portas ....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 quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://sqlblog.com/blogs/tibor_karaszi "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 > >
Other interesting topics
|
|||||||||||||||||||||||