Recherche avec plusieurs champs

Résolu
cs_akzo Messages postés 133 Date d'inscription dimanche 23 juin 2002 Statut Membre Dernière intervention 3 janvier 2015 - 17 avril 2008 à 11:40
JPGVB Messages postés 96 Date d'inscription mardi 29 mars 2005 Statut Membre Dernière intervention 10 mars 2011 - 18 avril 2008 à 12:30
bonjour a tous j'ai une petite question de requete sous vb6

SQL = "SELECT DISTINCT champrecherche FROM matableSave order by champrecherche "

jusque la ca fonctionne maintenant je fait

SQL = "SELECT DISTINCT champrecherche FROM matable WHERE Champ1 LIKE '%  text1.text  %' AND champ2 LIKE '% Text2.text  %'"
ou
SQL = "SELECT DISTINCT champrecherche FROM matable WHERE champ1= " &  text1.text & " AND champ2=" & Text2.text & ""
  
la ca fonctionne plus 
mon but et de faire une recherche dans un champ en fonction de X autre champ
merci pour votre aide
salutation
  

4 réponses

Kristof_Koder Messages postés 918 Date d'inscription vendredi 3 août 2007 Statut Membre Dernière intervention 27 octobre 2008 10
17 avril 2008 à 13:26
Comme cela, ce sera mieux :

SQL = "SELECT DISTINCT champrecherche FROM matable WHERE Champ1 LIKE '%" & text1.text & "%' AND champ2 LIKE '%" & Text2.text & "%'"
3
JPGVB Messages postés 96 Date d'inscription mardi 29 mars 2005 Statut Membre Dernière intervention 10 mars 2011 2
18 avril 2008 à 12:30
Bonjour, pour ton champ1 de type numérique il ne faut pas utiliser d'apostrophes (le LIKE est-il vraiment utile?) mais plutot:




... Champ1 LIKE %" &  text1.text & "% AND champ2 LIKE '%" & Text2.text & "%'"

Les apostrophes servent pour les champs de texte.
3
JPGVB Messages postés 96 Date d'inscription mardi 29 mars 2005 Statut Membre Dernière intervention 10 mars 2011 2
17 avril 2008 à 12:18




0
cs_akzo Messages postés 133 Date d'inscription dimanche 23 juin 2002 Statut Membre Dernière intervention 3 janvier 2015 3
18 avril 2008 à 10:42
Bonjour à tous
donc j'ai bien essayé la derniere proposition je n'ai plus la meme erreur j'ai maintenant type de données incompatible dans l'expression du critére
Pour info si ca peut aider mon champ1 est de type numérique et le champ 2 de type texte le champ de recherche est numérique

Salutation et merci pour la contribution de tous bonne journée
0
Rejoignez-nous