Hi Everyone, I'm working with VB6 and Access as a Database (local application) I no not get a query to work:
From the following query
StrConsulta = "SELECT * FROM MedReg WHERE IdService =" & IdService & StrDate & " ORDER BY IdMed"
to a Database in Access I get (In order to save space I changed column names):
A IdMed C D E F G
2, 405, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 405, 8ABR2009AB, 10, 8, SI, 4/8/2009
2, 407, 8ABR2009AB, 10, 8, SI, 4/8/2009
2, 407, 8ABR2009AC, 20, 15, SI, 4/8/2009
2, 622, 7ABR2009AA, 9, 5, SI, 4/7/2009
2, 622, 8ABR2009AA, 10, 8, SI, 4/8/2009
2, 622, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 643, 8ABR2009AC, 20, 15, SI, 4/8/2009
2, 643, 7ABR2009AC, 5, 4, SI, 4/8/2009
2, 643, 8ABR2009AC, 10, 8, SI, 4/8/2009
2, 644, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 644, 8ABR2009AC, 10, 8, SI, 4/8/2009
2, 644, 7ABR2009AA, 3, 3, SI, 4/8/2009
2, 685, 8ABR2009AA, 20, 15, SI, 4/8/2009
2, 685, 7ABR2009AA, 0, 0, SI, 4/8/2009
2, 685, 8ABR2009AA, 20, 15, SI, 4/8/2009
2, 685, 8ABR2009AA, 10, 8, SI, 4/8/2009
However What I need is something like:
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 405 AND
MedReg.IdMed = 407 AND
MedReg.IdMed = 622 AND
MedReg.IdMed = 643 AND
MedReg.IdMed = 644 AND
MedReg.IdMed = 685 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 405, 8ABR2009AC, 30, 18, SI, 4/8/2009
2, 407, 8ABR2009AB, 30, 23, SI, 4/8/2009
2, 622, 7ABR2009AA, 39, 23, SI, 4/7/2009
2, 643, 8ABR2009AC, 35, 27, SI, 4/8/2009
2, 644, 8ABR2009AC, 33, 22, SI, 4/8/2009
2, 685, 8ABR2009AA, 50, 15, SI, 4/8/2009
or
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 622 AND
MedReg.IdMed = 643 AND
MedReg.IdMed = 644 AND
MedReg.IdMed = 685 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 622, 7ABR2009AA, 39, 23, SI, 4/7/2009
2, 643, 8ABR2009AC, 35, 27, SI, 4/8/2009
2, 644, 8ABR2009AC, 33, 22, SI, 4/8/2009
2, 685, 8ABR2009AA, 50, 15, SI, 4/8/2009
or
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 405 AND
MedReg.IdMed = 407 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 405, 8ABR2009AC, 30, 18, SI, 4/8/2009
2, 407, 8ABR2009AB, 30, 23, SI, 4/8/2009
IdMed is what I'll be changing in the query according to my programming:
However it doesn't work in Access, The query does not send any data, not even an error, any idea?
From the following query
StrConsulta = "SELECT * FROM MedReg WHERE IdService =" & IdService & StrDate & " ORDER BY IdMed"
to a Database in Access I get (In order to save space I changed column names):
A IdMed C D E F G
2, 405, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 405, 8ABR2009AB, 10, 8, SI, 4/8/2009
2, 407, 8ABR2009AB, 10, 8, SI, 4/8/2009
2, 407, 8ABR2009AC, 20, 15, SI, 4/8/2009
2, 622, 7ABR2009AA, 9, 5, SI, 4/7/2009
2, 622, 8ABR2009AA, 10, 8, SI, 4/8/2009
2, 622, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 643, 8ABR2009AC, 20, 15, SI, 4/8/2009
2, 643, 7ABR2009AC, 5, 4, SI, 4/8/2009
2, 643, 8ABR2009AC, 10, 8, SI, 4/8/2009
2, 644, 8ABR2009AC, 20, 10, SI, 4/8/2009
2, 644, 8ABR2009AC, 10, 8, SI, 4/8/2009
2, 644, 7ABR2009AA, 3, 3, SI, 4/8/2009
2, 685, 8ABR2009AA, 20, 15, SI, 4/8/2009
2, 685, 7ABR2009AA, 0, 0, SI, 4/8/2009
2, 685, 8ABR2009AA, 20, 15, SI, 4/8/2009
2, 685, 8ABR2009AA, 10, 8, SI, 4/8/2009
However What I need is something like:
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 405 AND
MedReg.IdMed = 407 AND
MedReg.IdMed = 622 AND
MedReg.IdMed = 643 AND
MedReg.IdMed = 644 AND
MedReg.IdMed = 685 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 405, 8ABR2009AC, 30, 18, SI, 4/8/2009
2, 407, 8ABR2009AB, 30, 23, SI, 4/8/2009
2, 622, 7ABR2009AA, 39, 23, SI, 4/7/2009
2, 643, 8ABR2009AC, 35, 27, SI, 4/8/2009
2, 644, 8ABR2009AC, 33, 22, SI, 4/8/2009
2, 685, 8ABR2009AA, 50, 15, SI, 4/8/2009
or
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 622 AND
MedReg.IdMed = 643 AND
MedReg.IdMed = 644 AND
MedReg.IdMed = 685 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 622, 7ABR2009AA, 39, 23, SI, 4/7/2009
2, 643, 8ABR2009AC, 35, 27, SI, 4/8/2009
2, 644, 8ABR2009AC, 33, 22, SI, 4/8/2009
2, 685, 8ABR2009AA, 50, 15, SI, 4/8/2009
or
Running the following query should work well to get a "desired result":
SELECT
DISTINCT IdMed, SUM( MedReg.CantidadSolicitada), SUM( MedReg.CantidadRecibida) FROM
MedReg
WHERE
MedReg.IdService =2 AND
MedReg.IdMed = 405 AND
MedReg.IdMed = 407 AND
MedReg.DateBegin >= #04/01/2009# AND
MedReg.DateEnd <= #04/16/2009#
GROUP BY
IdMed
"desired result"
A IdMed C D E F G
2, 405, 8ABR2009AC, 30, 18, SI, 4/8/2009
2, 407, 8ABR2009AB, 30, 23, SI, 4/8/2009
IdMed is what I'll be changing in the query according to my programming:
However it doesn't work in Access, The query does not send any data, not even an error, any idea?