OVH Cloud OVH Cloud

Requete sql dans access

3 réponses
Avatar
John Smith
Bonjour,

J'ai un probleme de requete sql
Dim sSQL1 As String
sSQL1 = "SELECT detailrecette.Methode,"
sSQL1 = sSQL1 & " detailrecette.recette,"
sSQL1 = sSQL1 & " detailrecette.quantite,"
sSQL1 = sSQL1 & " detailrecette.unite,"
sSQL1 = sSQL1 & " receptioningre.Fournisseur As Fournisseur,"
sSQL1 = sSQL1 & " receptioningre.Lot,"
sSQL1 = sSQL1 & " receptioningre.termine,"
sSQL1 = sSQL1 & " DateDiff(""d"",Now(),[Dateexpiration]) AS Expr1,"
sSQL1 = sSQL1 & " detailrecette.Methode,"
sSQL1 = sSQL1 & " detailrecette.recette,"
sSQL1 = sSQL1 & " ingredient.ingredient,"
sSQL1 = sSQL1 & " receptioningre.Idingredient"
sSQL1 = sSQL1 & " FROM (detailrecette "
sSQL1 = sSQL1 & " INNER JOIN receptioningre "
sSQL1 = sSQL1 & " ON detailrecette.ingredient =
receptioningre.Idingredient) "
sSQL1 = sSQL1 & " INNER JOIN ingredient "
sSQL1 = sSQL1 & " ON receptioningre.Idingredient = ingredient.ID"
sSQL1 = sSQL1 & " WHERE (((detailrecette.Methode)='" & Combo1.Text &
"') "
sSQL1 = sSQL1 & " AND ((detailrecette.recette)='" & valrecette & "') "
sSQL1 = sSQL1 & " AND ((receptioningre.termine)=False) "
sSQL1 = sSQL1 & " AND ((DateDiff(""d"",Now(),[Dateexpiration]))>=0) "
sSQL1 = sSQL1 & " AND ((receptioningre.Idingredient)='" & tempiding &
"'))"
sSQL1 = sSQL1 & " ORDER BY receptioningre.Idingredient;"
Debug.Print sSQL1
valeur sSQL1
MsgBox recvaleur("Fournisseur")

Voici le debug.print
SELECT detailrecette.Methode, detailrecette.recette,
detailrecette.quantite, detailrecette.unite, receptioningre.Fournisseur As
Fournisseur, receptioningre.Lot, receptioningre.termine,
DateDiff("d",Now(),[Dateexpiration]) AS Expr1, detailrecette.Methode,
detailrecette.recette, ingredient.ingredient, receptioningre.Idingredient
FROM (detailrecette INNER JOIN receptioningre ON
detailrecette.ingredient = receptioningre.Idingredient) INNER JOIN
ingredient ON receptioningre.Idingredient = ingredient.ID WHERE
(((detailrecette.Methode)='M-TURB-1.0') AND
((detailrecette.recette)='Solution Précipité') AND
((receptioningre.termine)=False) AND
((DateDiff("d",Now(),[Dateexpiration]))>=0) AND
((receptioningre.Idingredient)='1')) ORDER BY receptioningre.Idingredient;

Ca platte en me disant data type mismatch

J,ai trouve la ligne qui ne marche
receptioningre.Idingredient)='1'
dans ma table idingredient est en format number

Je voudrais savoir comment changer ma ligne pour que ca marche

Merci

3 réponses

Avatar
Fred
Dans son message pjvCe.674$
John Smith nous dit :

Bonjour,



Bonjour,

J'ai un probleme de requete sql


[...]
sSQL1 = sSQL1 & " AND
((DateDiff(""d"",Now(),[Dateexpiration]))>=0) " sSQL1 = sSQL1 & "
AND ((receptioningre.Idingredient)='" & tempiding & "'))"


[...]

Ca platte en me disant data type mismatch

J,ai trouve la ligne qui ne marche
receptioningre.Idingredient)='1'
dans ma table idingredient est en format number



Peut-être simplement enlever les apsotrophes ?
AND ((receptioningre.Idingredient)=" & tempiding & "))"


--
Fred
http://www.cerbermail.com/?3kA6ftaCvT
Avatar
Christian Hubert-Hugoud
Bonjour,

Une bonne combine consiste à copier le SQL et à créer une requête dans
ACCESS directement, en y collant le SQL (ily a une fonction qui permet de
travailler en SQL). Après quoi on run la requête et ACCESS indique où cela
ne fonctionne pas.

Ce que je tenterais :

receptioningre.Idingredient)='1' devient

receptioningre.Idingredient)=1

Christian


"John Smith" a écrit dans le message de news:
pjvCe.674$
Bonjour,

J'ai un probleme de requete sql
Dim sSQL1 As String
sSQL1 = "SELECT detailrecette.Methode,"
sSQL1 = sSQL1 & " detailrecette.recette,"
sSQL1 = sSQL1 & " detailrecette.quantite,"
sSQL1 = sSQL1 & " detailrecette.unite,"
sSQL1 = sSQL1 & " receptioningre.Fournisseur As Fournisseur,"
sSQL1 = sSQL1 & " receptioningre.Lot,"
sSQL1 = sSQL1 & " receptioningre.termine,"
sSQL1 = sSQL1 & " DateDiff(""d"",Now(),[Dateexpiration]) AS Expr1,"
sSQL1 = sSQL1 & " detailrecette.Methode,"
sSQL1 = sSQL1 & " detailrecette.recette,"
sSQL1 = sSQL1 & " ingredient.ingredient,"
sSQL1 = sSQL1 & " receptioningre.Idingredient"
sSQL1 = sSQL1 & " FROM (detailrecette "
sSQL1 = sSQL1 & " INNER JOIN receptioningre "
sSQL1 = sSQL1 & " ON detailrecette.ingredient =
receptioningre.Idingredient) "
sSQL1 = sSQL1 & " INNER JOIN ingredient "
sSQL1 = sSQL1 & " ON receptioningre.Idingredient = ingredient.ID"
sSQL1 = sSQL1 & " WHERE (((detailrecette.Methode)='" & Combo1.Text &
"') "
sSQL1 = sSQL1 & " AND ((detailrecette.recette)='" & valrecette & "') "
sSQL1 = sSQL1 & " AND ((receptioningre.termine)úlse) "
sSQL1 = sSQL1 & " AND ((DateDiff(""d"",Now(),[Dateexpiration]))>=0) "
sSQL1 = sSQL1 & " AND ((receptioningre.Idingredient)='" & tempiding &
"'))"
sSQL1 = sSQL1 & " ORDER BY receptioningre.Idingredient;"
Debug.Print sSQL1
valeur sSQL1
MsgBox recvaleur("Fournisseur")

Voici le debug.print
SELECT detailrecette.Methode, detailrecette.recette,
detailrecette.quantite, detailrecette.unite, receptioningre.Fournisseur
As Fournisseur, receptioningre.Lot, receptioningre.termine,
DateDiff("d",Now(),[Dateexpiration]) AS Expr1, detailrecette.Methode,
detailrecette.recette, ingredient.ingredient,
receptioningre.Idingredient FROM (detailrecette INNER JOIN
receptioningre ON detailrecette.ingredient =
receptioningre.Idingredient) INNER JOIN ingredient ON
receptioningre.Idingredient = ingredient.ID WHERE
(((detailrecette.Methode)='M-TURB-1.0') AND
((detailrecette.recette)='Solution Précipité') AND
((receptioningre.termine)úlse) AND
((DateDiff("d",Now(),[Dateexpiration]))>=0) AND
((receptioningre.Idingredient)='1')) ORDER BY
receptioningre.Idingredient;

Ca platte en me disant data type mismatch

J,ai trouve la ligne qui ne marche
receptioningre.Idingredient)='1'
dans ma table idingredient est en format number

Je voudrais savoir comment changer ma ligne pour que ca marche

Merci





Avatar
Driss HANIB
tout à fait d'accord,

les apostrophes sont les équivalents des chaines pour la requête SQL. Si tu
veux mettre un numérique il ne doit pas y avoir d'apostrophe.
ces apostrophes permettent de mettre une chaine dans ta requête elle même
entourée de guillemets.

Driss

"Christian Hubert-Hugoud" a écrit dans le message
de news:
Bonjour,

Une bonne combine consiste à copier le SQL et à créer une requête dans
ACCESS directement, en y collant le SQL (ily a une fonction qui permet de
travailler en SQL). Après quoi on run la requête et ACCESS indique où cela
ne fonctionne pas.

Ce que je tenterais :

receptioningre.Idingredient)='1' devient

receptioningre.Idingredient)=1

Christian


"John Smith" a écrit dans le message de news:
pjvCe.674$
> Bonjour,
>
> J'ai un probleme de requete sql
> Dim sSQL1 As String
> sSQL1 = "SELECT detailrecette.Methode,"
> sSQL1 = sSQL1 & " detailrecette.recette,"
> sSQL1 = sSQL1 & " detailrecette.quantite,"
> sSQL1 = sSQL1 & " detailrecette.unite,"
> sSQL1 = sSQL1 & " receptioningre.Fournisseur As Fournisseur,"
> sSQL1 = sSQL1 & " receptioningre.Lot,"
> sSQL1 = sSQL1 & " receptioningre.termine,"
> sSQL1 = sSQL1 & " DateDiff(""d"",Now(),[Dateexpiration]) AS Expr1,"
> sSQL1 = sSQL1 & " detailrecette.Methode,"
> sSQL1 = sSQL1 & " detailrecette.recette,"
> sSQL1 = sSQL1 & " ingredient.ingredient,"
> sSQL1 = sSQL1 & " receptioningre.Idingredient"
> sSQL1 = sSQL1 & " FROM (detailrecette "
> sSQL1 = sSQL1 & " INNER JOIN receptioningre "
> sSQL1 = sSQL1 & " ON detailrecette.ingredient > > receptioningre.Idingredient) "
> sSQL1 = sSQL1 & " INNER JOIN ingredient "
> sSQL1 = sSQL1 & " ON receptioningre.Idingredient = ingredient.ID"
> sSQL1 = sSQL1 & " WHERE (((detailrecette.Methode)='" & Combo1.Text &
> "') "
> sSQL1 = sSQL1 & " AND ((detailrecette.recette)='" & valrecette & "')


"
> sSQL1 = sSQL1 & " AND ((receptioningre.termine)úlse) "
> sSQL1 = sSQL1 & " AND ((DateDiff(""d"",Now(),[Dateexpiration]))>=0)


"
> sSQL1 = sSQL1 & " AND ((receptioningre.Idingredient)='" & tempiding


&
> "'))"
> sSQL1 = sSQL1 & " ORDER BY receptioningre.Idingredient;"
> Debug.Print sSQL1
> valeur sSQL1
> MsgBox recvaleur("Fournisseur")
>
> Voici le debug.print
> SELECT detailrecette.Methode, detailrecette.recette,
> detailrecette.quantite, detailrecette.unite,


receptioningre.Fournisseur
> As Fournisseur, receptioningre.Lot, receptioningre.termine,
> DateDiff("d",Now(),[Dateexpiration]) AS Expr1, detailrecette.Methode,
> detailrecette.recette, ingredient.ingredient,
> receptioningre.Idingredient FROM (detailrecette INNER JOIN
> receptioningre ON detailrecette.ingredient > > receptioningre.Idingredient) INNER JOIN ingredient ON
> receptioningre.Idingredient = ingredient.ID WHERE
> (((detailrecette.Methode)='M-TURB-1.0') AND
> ((detailrecette.recette)='Solution Précipité') AND
> ((receptioningre.termine)úlse) AND
> ((DateDiff("d",Now(),[Dateexpiration]))>=0) AND
> ((receptioningre.Idingredient)='1')) ORDER BY
> receptioningre.Idingredient;
>
> Ca platte en me disant data type mismatch
>
> J,ai trouve la ligne qui ne marche
> receptioningre.Idingredient)='1'
> dans ma table idingredient est en format number
>
> Je voudrais savoir comment changer ma ligne pour que ca marche
>
> Merci
>
>
>