OVH Cloud OVH Cloud

EXISTS dans requete SQL

6 réponses
Avatar
I.G.LOG
Bonjour,
j'essaie de lister les articles pour lesquels il y a eu une livraison durant
une période donnée.
La requete suivante ne me donne rien alors qu'il y a bien des lignes de
livraison pour cette période (depuis 1800) !!!!!

select SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = 1
and ARTSTOCK.ETAT = 1
and ARTSTOCK.IDSTOCK = 1
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and exists (select IDARTICLE from FOULIVLG,FOULIV where FOULIVLG.IDARTICLE =
ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between '18000101' and '20050930')
order by ABRCONST,REFCONST,ETAT

j'ai essayé la sous-requete seule, elle me renvoit bien les lignes voulues.
Sans la sous-requete, idem ca marche correctement.
Il y a bien un problème avec la clause EXISTS ?!!

Nota: je suis sous Windev 8 33t

6 réponses

Avatar
mat
I.G.LOG wrote:
Bonjour,
j'essaie de lister les articles pour lesquels il y a eu une livraison durant
une période donnée.
La requete suivante ne me donne rien alors qu'il y a bien des lignes de
livraison pour cette période (depuis 1800) !!!!!

select SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = 1
and ARTSTOCK.ETAT = 1
and ARTSTOCK.IDSTOCK = 1
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and exists (select IDARTICLE from FOULIVLG,FOULIV where FOULIVLG.IDARTICLE > ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between '18000101' and '20050930')
order by ABRCONST,REFCONST,ETAT

j'ai essayé la sous-requete seule, elle me renvoit bien les lignes voulues.
Sans la sous-requete, idem ca marche correctement.
Il y a bien un problème avec la clause EXISTS ?!!




en tout cas en ce qui me concerne. Je n'ai jamais réussi à l'utiliser.

Salutations
mat
Avatar
I.G.LOG
> Remplace ton exists par un count(*) et un >0, ca fonctionnera de la
même manière et ça marchera ptete mieux...

Sinon tu fais une jointure sur les tables de livraison avec un
distinct, mais ca sera peut être plus lent.





Bonjour et merci pour la réponse,
J'ai essayé le code suivant (avec ou sans les parenthèses) dans la requete
qui ne fonctionne pas (requete pas admise par WD)

...
and ((select count(*) from FOULIVLG,FOULIV where FOULIVLG.IDARTICLE ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between {pDateDe} and {pDateA}) > 0)
...

Quelle doit être la syntaxe pour tester la valeur du count() ?

Encore merci
Avatar
I.G.LOG
Suite de mes essais pour tester les articles pour lesquels il y a une
livraison dans une période donnée.

J'ai même essayé en remplaçant le EXISTS par IN et même = , rien n'y fait.
Avec le code ci après, on dirait que la requete s'exécute sans jamais sortir
(attendu plusieurs minutes d'attente, sans succès)
Il n'y a aucun moyen de sélectionner les enregistrements pour lesquels il
existe une ligne de livraison ou une sortie de stock ?
Si qqun connaît une astuce ?
Merci à tous

NB: essais réalisés avec WD8 33t et WD9 34j: problèmes identiques !!!


select SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = {pNumSoc}
and ARTICLE.REFTA between {pDe} and {pA}
and ARTSTOCK.ETAT = {pEtat}
and ARTICLE.CODEREM = {pCodeRem}
and ARTSTOCK.IDSTOCK = {pNumMag}
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and ARTICLE.IDARTICLE in (select top 1 IDARTICLE from FOULIVLG,FOULIV where
FOULIVLG.IDARTICLE = ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between {pDateDe} and {pDateA})
//and ARTICLE.IDARTICLE in (select top 1 IDARTICLE from ARTSTOCK as
Stock,STOCKSOR where Stock.IDARTICLE = ARTICLE.IDARTICLE
//and STOCKSOR.IDARTSTOCK = Stock.IDARTSTOCK
//and STOCKSOR.DATE between {pDateDe} and {pDateA})
order by ABRCONST,REFCONST,ETAT
Avatar
Vincent
I.G.LOG a écrit :
Suite de mes essais pour tester les articles pour lesquels il y a une
livraison dans une période donnée.

J'ai même essayé en remplaçant le EXISTS par IN et même = , rien n'y fait.
Avec le code ci après, on dirait que la requete s'exécute sans jamais sortir
(attendu plusieurs minutes d'attente, sans succès)
Il n'y a aucun moyen de sélectionner les enregistrements pour lesquels il
existe une ligne de livraison ou une sortie de stock ?
Si qqun connaît une astuce ?
Merci à tous

NB: essais réalisés avec WD8 33t et WD9 34j: problèmes identiques !!!





Je pense qu'il ne te reste hélas que la solution du distinct et de la
jointure. C'est sûr, c'est gourmand.

select distinct SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC, FOULIVLG,FOULIV
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = {pNumSoc}
and ARTICLE.REFTA between {pDe} and {pA}
and ARTSTOCK.ETAT = {pEtat}
and ARTICLE.CODEREM = {pCodeRem}
and ARTSTOCK.IDSTOCK = {pNumMag}
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and FOULIVLG.IDARTICLE = ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between {pDateDe} and {pDateA})

Normalement, tu obtiens la liste des livraisons. (j'ai pas testé)
Avatar
I.G.LOG
> Je pense qu'il ne te reste hélas que la solution du distinct et de la
jointure. C'est sûr, c'est gourmand.

select distinct SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC, FOULIVLG,FOULIV
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = {pNumSoc}
and ARTICLE.REFTA between {pDe} and {pA}
and ARTSTOCK.ETAT = {pEtat}
and ARTICLE.CODEREM = {pCodeRem}
and ARTSTOCK.IDSTOCK = {pNumMag}
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and FOULIVLG.IDARTICLE = ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between {pDateDe} and {pDateA})

Normalement, tu obtiens la liste des livraisons. (j'ai pas testé)



Bonjour,
Malheureusement je ne cherche pas la liste des livraisons mais les articles
pour lesquels il ya eu une livraison OU une sortie de stock dans la période
donnée !
Je ne sais pas si avec les jointures j'arriverai au résultat.
En tous cas, bizarre que les clauses EXISTS, IN ... ne marchent pas sur HF
classic ni en WD 8 ni en 9 !!!
Merci
Avatar
Vincent
I.G.LOG a écrit :
Je pense qu'il ne te reste hélas que la solution du distinct et de la
jointure. C'est sûr, c'est gourmand.

select distinct SOCIETE.RAISON, SOCIETE.NUMSOC,
ARTSTOCK.IDARTICLE, ARTSTOCK.ETAT, ARTSTOCK.QTE, ARTSTOCK.PMP,
ARTSTOCK.QTEREAPPRO, ARTSTOCK.QTEMINI, ARTSTOCK.IDSTOCK,
ARTICLE.CODEREM, ARTICLE.DESIGNATION, ARTICLE.ABRCONST, ARTICLE.REFCONST,
CONSTRUC.RAISON as Constructeur
from SOCIETE, ARTSTOCK, ARTICLE, CONSTRUC, FOULIVLG,FOULIV
where ARTSTOCK.NUMSOC = SOCIETE.NUMSOC
and ARTICLE.IDARTICLE = ARTSTOCK.IDARTICLE
and ARTSTOCK.IDCLIENT = 0
and SOCIETE.NUMSOC = {pNumSoc}
and ARTICLE.REFTA between {pDe} and {pA}
and ARTSTOCK.ETAT = {pEtat}
and ARTICLE.CODEREM = {pCodeRem}
and ARTSTOCK.IDSTOCK = {pNumMag}
and ARTSTOCK.IDCLIENT = 0 and ARTSTOCK.INTERNE = 1
and CONSTRUC.ABRCONST = ARTICLE.ABRCONST
and FOULIVLG.IDARTICLE = ARTICLE.IDARTICLE
and FOULIV.IDFOULIV = FOULIVLG.IDFOULIV
and FOULIV.DATE between {pDateDe} and {pDateA})

Normalement, tu obtiens la liste des livraisons. (j'ai pas testé)




Bonjour,
Malheureusement je ne cherche pas la liste des livraisons mais les articles
pour lesquels il ya eu une livraison OU une sortie de stock dans la période
donnée !
Je ne sais pas si avec les jointures j'arriverai au résultat.
En tous cas, bizarre que les clauses EXISTS, IN ... ne marchent pas sur HF
classic ni en WD 8 ni en 9 !!!
Merci





Avec des jointures tu peux y arriver.
Comme la livraison ou la sortie de stock est facultative, utilise LEFT
OUTER JOIN pour la jointure.

Peux tu envoyer une description du mcd ?

Vincent.