Bonjour les amis,

Depuis peu j'ai découvert la construction des requetes SQL sur fichiers HF que je trouve super génial.

Par contre je galère pour trouver la bonne syntaxe pour construire une requete si simple (sur un seul fichier) avec plusieurs conditions. Dans certains cas la chaine obtenue est inexploitable.

Ci dessous la structure du fichier


Voici un premier resultat de la requete lorsque toutes les conditions sont remplies - Apparemment cela pourrait fonctionner?


Et ci dessous lorsque je laisse en blanc certaines conditions (des AND reste un peu partout)


Voici le code que j'utilise:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
PROCEDURE Construire_Rqte()
Sablier()
 
L_phraseSQL est une chaîne     = "SELECT * "
L_phraseSQL+= " FROM Basexterne "
 
SI SansEspace(SAI_Rech_NomCommercial)<>"" ALORS
	L_phraseSQL+=" WHERE"	
FIN
 
SELON COMBO_NomCommercial
	CAS 1
		SI SansEspace(SAI_Rech_NomCommercial)<>"" ALORS	L_phraseSQL+=" Nom_Commercial LIKE'"+"%"+SAI_Rech_NomCommercial+"%"+"'"
	CAS 2
		SI SansEspace(SAI_Rech_NomCommercial)<>"" ALORS L_phraseSQL+=" Nom_Commercial ='"+SAI_Rech_NomCommercial
	AUTRE CAS
 
FIN	
 
SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
	L_phraseSQL+=" AND"
SINON
	L_phraseSQL+=" WHERE"
FIN
 
SELON COMBO_NomClinique
 
	CAS 1
		SI SansEspace(SAI_Rech_DCI)<>"" ALORS L_phraseSQL+=" Nom_Clinique LIKE'"+"%"+SAI_Rech_DCI+"%"+"'"
 
	CAS 2
		SI SansEspace(SAI_Rech_DCI)<>"" ALORS L_phraseSQL+=" Nom_Clinique ="+SAI_Rech_DCI
 
	AUTRE CAS
 
FIN
 
SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
	L_phraseSQL+=" AND"
SINON
	L_phraseSQL+=" WHERE"
FIN
 
SELON COMBO_Forme
 
	CAS 2		//Enfant
		L_phraseSQL+=" Forme_Enfant =1"
 
	CAS 3		//Adulte
		L_phraseSQL+=" Forme_Adulte =1"
 
	CAS 4		//Nourrisson
		L_phraseSQL+=" Forme_Nourrisson =1"
 
	AUTRE CAS
 
FIN
 
SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
	L_phraseSQL+=" AND"
SINON
	L_phraseSQL+=" WHERE"
FIN
 
SELON COMBO_Fournisseur
 
	CAS 2		//Laborex
		L_phraseSQL+=" Fournisseur_Laborex =1"
 
	CAS 3		//Copharma
		L_phraseSQL+=" Fournisseur_Copharma =1"
 
	CAS 4		//Africalab
		L_phraseSQL+=" Fournisseur_Africalab =1"
 
	CAS 5		//Autres
		L_phraseSQL+=" Fournisseur_Autres =1"
 
	AUTRE CAS
 
FIN
 
 
SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
	L_phraseSQL+=" AND"
SINON
	L_phraseSQL+=" WHERE"
FIN
 
 
SI COMBO_Prix_Cession>0 ALORS
	SI SAI_Montant_mini>0 ALORS L_phraseSQL+= " Prix_Cession>='"+SAI_Montant_mini+"'"
	SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
		L_phraseSQL+=" AND"
	SINON
		L_phraseSQL+=" WHERE"
	FIN
 
	SI SAI_Montant_maxi>0 ALORS L_phraseSQL+= " Prix_Cession<='"+SAI_Montant_maxi+"'"
	SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
		L_phraseSQL+=" AND"
	SINON
		L_phraseSQL+=" WHERE"
	FIN
 
FIN
 
 
 
SI COMBO_Prix_Public>0 ALORS
	SI SAI_Montant_mini1>0 ALORS L_phraseSQL+= " Prix_Public>='"+SAI_Montant_mini1+"'"
	SI ChaîneOccurrence(L_phraseSQL,"WHERE")>0 ALORS
		L_phraseSQL+=" AND"
	SINON
		L_phraseSQL+=" WHERE"
	FIN
	SI SAI_Montant_maxi1>0 ALORS L_phraseSQL+= " Prix_Public<='"+SAI_Montant_maxi1+"'"
 
FIN
 
Info(L_phraseSQL)
Et voici la fenetre

http://www.sendspace.com/file/n01syz

Merci d'avance à tous