You are here: Re: Need help with CONVERT function « MsSQL Server « IT news, forums, messages
Re: Need help with CONVERT function

Posted by Plamen Ratchev on 02/28/07 16:15

In order to drop the time portion of a date via the CONVERT function you
have to do a double convert, first to character type and then to datetime.
Here is how it will look:

WHERE ( CONVERT(DATETIME, CONVERT(CHAR(10), tblESEnrollments.DTStamp, 101))
>= @StartDate) AND
( CONVERT(DATETIME, CONVERT(CHAR(10), tblESEnrollments.DTStamp,
101)) <= @StopDate)

However, a better approach is to use the DATEDIFF function as it will be
more efficient than converting and it will allow you to utilize any indexes
on the DTStamp column. Here is how it will look:

WHERE tblESEnrollments.DTStamp >= DATEDIFF(day, 0, @StartDate) AND
tblESEnrollments.DTStamp <= DATEDIFF(day, -1, @StopDate)

HTH,

Plamen Ratchev
http://www.SQLStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация