MySql query using WHERE... IN clauses.

MySql query using WHERE... IN clauses.

Postby FranciscoA » Thu Oct 10, 2019 8:12 pm

Hello friends.
The following code works for me:
Code: Select all  Expand view  RUN
SELECT vendedor, SUM(gtot) Total_Ventas   FROM facturah
WHERE vendedor IN ( "FRANCISCO","ROBERTO" )  AND fecha BETWEEN '2012-01-01' AND '2012-06-30'
GROUP BY vendedor   ORDER BY vendedor,fecha ;
 


However, I want to automate it by sending a variable with the relevant data:
This does not work. In addition to trying it in many other ways.
Code: Select all  Expand view  RUN
cCad := "FRANCISCO,ROBERTO"  
WHERE vendedor IN ( '"+cCad+"' )  AND fecha BETWEEN '2012-01-01' AND '2012-06-30'
 


It runs without errors, but does not show any results.

Can you tell me what is the right way?
Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: MySql query using WHERE... IN clauses.

Postby carlos vargas » Thu Oct 10, 2019 8:27 pm

Code: Select all  Expand view  RUN

cCad := "FRANCISCO,ROBERTO"  
WHERE vendedor IN ( '"+cCad+"' )  AND fecha BETWEEN '2012-01-01' AND '2012-06-30'
 

se veria asi:
WHERE vendedor IN ( '"FRANCISCO,ROBERTO"' ) AND fecha BETWEEN '2012-01-01' AND '2012-06-30'

y deberia verse asi:
WHERE vendedor IN ( "FRANCISCO","ROBERTO" )  AND fecha BETWEEN '2012-01-01' AND '2012-06-30'
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: MySql query using WHERE... IN clauses.

Postby carlos vargas » Thu Oct 10, 2019 8:31 pm

Code: Select all  Expand view  RUN

cCad:=['CARLOS','VARGAS']
WHERE vendedor IN ( "+cCad+" )  AND fecha BETWEEN '2012-01-01' AND '2012-06-30'
 


Code: Select all  Expand view  RUN

?"WHERE vendedor IN (" + cCad+ ") AND fecha BETWEEN '2012-01-01' AND '2012-06-30'"
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: MySql query using WHERE... IN clauses.

Postby FranciscoA » Thu Oct 10, 2019 9:33 pm

Carlos.
Gracias, ahora ya está funcionando.
Saludos.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 44 guests