Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avoiding parentheses
Message
 
 
À
22/09/2015 13:41:11
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01624934
Message ID:
01624939
Vues:
70
This message has been marked as the solution to the initial question of the thread.
>In this WHERE clause, I have parentheses:
>
>
>WHERE Client.NoProvince=@NoProvince AND
> NOT (Client.Status<@Status AND Client.NoStatus=@NoStatus) AND
> NOT (Client.Status<@Status2 AND Client.NoStatus=@NoStatus2) AND
> NOT (Client.Status<@Status3 AND Client.NoStatus=@NoStatus3) AND
> NOT (Client.Status<@Status4 AND Client.NoStatus=@NoStatus4) AND
> Client.NoCountry IN (1,2,3,4,5,6,7) AND
> Client.FirstName LIKE @LXList1Clm_No
>
>
>Would there be a way to avoid the parentheses? I see the execution is much smarter without those.

So, can you translate these conditions into English? Is it the same as

When NoStatus = @NoStatus you want rows with Status >=@Status
for NoStatus = @NoStatus1 you want rows with Status >=@Status1

etc.

If my interpretation is correct and NoStatus can only be one of the 4 statuses, then you can convert this condition into CASE based.
1 = case Client.NoStatus when @NoStatus
then case when Client.Status >= @Status then 1 else 0 end
when @NoStatus1
then case when Client.Status >= @Status1 then 1 else 0 end
etc.
end
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