Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Eliminating WHERE clauses with NOT
Message
De
05/11/2014 01:58:50
 
 
À
04/11/2014 11:24:14
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:
01610458
Message ID:
01610500
Vues:
54
>>It's boolean algebra
>>
>>
>>NOT ( A and B) 
>>
>>is
>>
>>NOT(A) or NOT(B)
>>
>>
>>
>>So
>>
>>NOT (Client.NoStatus=@NoStatus AND Client.ModDate<@ModDate)
>>
>>NOT( Client.NoStatus=@NoStatus ) OR NOT(Client.ModDate<@ModDate)
>>
>>is
>>(Client.NoStatus <> @NoStatus) OR ( Client.ModDate>= @ModDate )
>>
>>
>>
>>Also
>>
>>
>>NOT ( A or B)
>>is
>>NOT(A) and NOT(B)
>>
>
>Thanks, this provides valuable information.
>
>If you look at Message #1610467, you will see a more realistic command I have to execute.
>
>Based on your reply, from that referred message, does this mean the second command, the one without the NOT clauses, wouldn't need any parentheses?


I think the second statement needs parentheses. Without, the ANDs will be executed before the ORs

http://msdn.microsoft.com/en-us/library/ms190276.aspx

Your statement
SELECT Client.Numero FROM Client (NOLOCK)
 WHERE (Client.ModDate>=@ModDate OR Client.NoStatus<>@NoStatus) AND
  (Client.ModDate>=@ModDate2 OR Client.NoStatus<>@NoStatus2) AND
  (Client.ModDate>=@ModDate3 OR Client.NoStatus<>@NoStatus3)
without parentheses would be
SELECT Client.Numero FROM Client (NOLOCK)
 WHERE Client.ModDate>=@ModDate OR Client.NoStatus<>@NoStatus AND
  Client.ModDate>=@ModDate2 OR Client.NoStatus<>@NoStatus2 AND
  Client.ModDate>=@ModDate3 OR Client.NoStatus<>@NoStatus3
and is the same as
SELECT Client.Numero FROM Client (NOLOCK)
 WHERE Client.ModDate>=@ModDate 
      OR ( Client.NoStatus<>@NoStatus AND  Client.ModDate>=@ModDate2)
     OR (Client.NoStatus<>@NoStatus2 AND  Client.ModDate>=@ModDate3 )
    OR (Client.NoStatus<>@NoStatus3)
which is different
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform