Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a better way of selecting information for a dat
Message
De
25/04/2007 00:10:29
Peter Wagner
Point Informática Ltda.
Limeira, Brésil
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01219598
Message ID:
01219631
Vues:
16
Einar,
I thing my method is faster just because it uses only 1 Function (CONVERT) and your method uses 3 (YEAR, MONTH, DAY). (have not compared the statements)

But both method should use an index scan (if an index exist in the column) to get the records you want, just give a look at the Extimated Execution Plan for any statement you try to see the best Execution Plan.

Maybe SQL Server is smart enough to make the cost the same, and I thing your method would be translated to something similar as Sergey's sample by SQL Server.

[ ]'s
Peter


>Peter,
>Thanks for your reply. I have to look into the convert funtion more. Do you think your method is better, i.e., faster than my method?
>
>Thanks,
>Einar
>
>>see the sample...
>>
>>
>>select orderid from orders where Convert(char(10),orderdate,112) = '19960829'
>>
>>
>>gives this...
>>
>>
>>SELECT	[Id]
>>FROM	[MyTable]
>>WHERE	CONVERT(CHAR(10),DateField,112) = @DateField
>>
>>
>>Code 112 in convert means ISO, but you can use 110 for USA mm-dd-yy, see BOL.
>>
>>[ ]'s
>>Peter
>>
>>>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?
>>>
>>>Thanks,
>>>Einar
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform