Today is Wednesday and it is before 10 am; therefore I am allowed to ask a stupid question <g>. I know that since Sergey and Cetin (two guys with "above average" <g> IQ) replied with basically the same method, I don't doubt that they have the right suggestion.
But why not use "==" when comparing DateField and @DateOnly?
>Should be faster if you have an index on the datetime field. It also doesn't look more complex to me, I use this idea everytime in VFP, though.
>
>>Thanks for your reply Sergey. As always I value your response a lot. I find your syntaxt more difficult to read than my method, but the big question is: Is your way better, i.e., faster than my method?
>>
>>Thanks,
>>Einar
>>
>>>
>>>DECLARE @DateOnly datetime
>>>SET @DateOnly = DATEADD(dd, DATEDIFF(dd, dt, @DateField), dt)
>>>...
>>>WHERE DateField >= @DateOnly AND DateField < @DateOnly + 1
>>>
>>>
>>>>Consider the following select statement:
>>>>
>>>>SELECT [Id]
>>>>FROM [MyTable]
>>>>WHERE YEAR(DateField) = YEAR(@DateField) AND
>>>> MONTH(DateField) = MONTH(@DateField) AND
>>>> DAY(DateField) = DAY(@DateField)
>>>>
>>>>
>>>>I want to select the records that have the same date as the parameter, but I do not care about the time part of the field or parameter.
>>>>Is there another (better) way of doing this?
>>>>
>>>>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham