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
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
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: 2158
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

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: 1720
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

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


Code: Select all  Expand view

?"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: 1720
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: 2158
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: No registered users and 96 guests