Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Microsoft SQL Server
Versions des environnements
SQL Server:
SQL Server 2012
>>I would recommend dynamic SQL in any case. You'd only optimize the parts of the where clause that need it.
>
>What do you mean by "You'd only optimize the parts of the where clause that need it"?
If you create a where like
(@MinDate is null OR @MinDate < = Date) and
(@MaxDate is null OR @MaxDate > = Date) and
(@MinAmount is null OR @MinAmount > = Amount) and
SQL is doing a lot of extra work internally. If you construct the query dynamically so that in the case where @MinAmount is not passed you execute
(@MinDate is null OR @MinDate < = Date) and
(@MaxDate is null OR @MaxDate > = Date)
The optimizer will not waste time even thinking about MinAmount. :)
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement