6
votes

Exclure les enregistrements vérifiant deux conditions

select * from table_name
 where BaseDocEntry=15 and BaseDocType='PRRH' and ItemCode='TestStudy2'
   and WhseCode='01' and (currentdoctype<>'PUSH' and CurrentDocEntry<>15)
According to the query I have written above, the data from INS2 will be fetched excluding the currentdoctype [PUSH] and all data where CurrentDocEntry is not 15. What I expect my query to be is, it must exclude the data only if this combination i.e. currentdoctype=PUSH and CurrentDocEntry=15 are occurring in the same row, then exclude that row. Can you fix this query ?

0 commentaires

3 Réponses :


22
votes

Utilisez ceci:

and not (currentdoctype='PUSH' and CurrentDocEntry=15)


0 commentaires

1
votes

Étant donné que vous utilisez et et non ou la requête est excluant lorsque CurrentDoctype est différent de "Push" et CurrentDocentry différent de 15.

Si tu veux CurrentDoctype = Push and CurrentDocentry = 15 Il suffit de mettre ces conditions à la place: xxx


0 commentaires

0
votes

Dans certains cas où ne fonctionne pas, vous ne pouvez pas le résoudre en utilisant un cas simple et où la clause. Cela n'exclurea que les cas d'actualisationDoctype = 'Push' et CurrentDocentry = 15.

SELECT *,
CASE
WHEN currentdoctype ='PUSH' AND CurrentDocEntry = 15 THEN 'c1'
ELSE 'c2'
END AS com_con
FROM table_name
WHERE  BaseDocEntry=15 AND BaseDocType='PRRH' AND ItemCode='TestStudy2'
   AND WhseCode='01' AND com_con = 'c2';


0 commentaires