Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimization with a date condition
Message
 
 
À
22/03/2011 17:21:31
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01504587
Message ID:
01504590
Vues:
33
>If I have a script like this:
>
>
>SELECT MyTable.MyField FROM MyDatabase.dbo.MyTable WHERE MyTable.AddDate>'2011/03/22 17:08:26'
>
>
>...it executes instantly. The result is zero record.
>
>But, if I parameterize it such as:
>
>
>DECLARE @Date datetime
>
>SET @Date='2011/03/22 17:08:26'
>
>SELECT MyTable.MyField FROM MyDatabase.dbo.MyTable WHERE MyTable.AddDate>@Date
>
>
>...it takes a while. And, the result is still zero record.
>
>I tried to make the declaration char and nvarchar but that did not help.
>
>There is something I am missing here.

Try adding

option (recompile) to the query.

http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/a2030652-800b-48dd-8857-5e6e60658a6e

http://social.msdn.microsoft.com/forums/en-us/transactsql/thread/CFA976DB-2D12-4D80-B4B2-CEFFB80B7F6C
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform