Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better way of selecting information for a dat
Message
From
25/04/2007 08:58:05
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01219598
Message ID:
01219708
Views:
12
Dmitry,
SQL server is compatible with ANSISQL92. IOW to SQL server "=" and "==" are same (ANSI on).
Cetin

>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?
>>>>>
>>>>>
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform