Cadena extensa TEXT ENDTEXT - ( SOLUCIONADO )

Cadena extensa TEXT ENDTEXT - ( SOLUCIONADO )

Postby leandro » Thu Dec 12, 2019 1:47 am

Buenas noches para todos, en este momento me surge la necesidad que crear una cadena de texto bastante extensa, para realizar una consulta sql, pero requiero reemplazar algunos datos dentro de la cadena de texto, buscando en el foro, encontré la forma de escribir la super consulta, pero lo que no logro es reemplazar valores dentro del contenido de la cadena.

Code: Select all  Expand view  RUN

**********************************
*MOVIMIENTO DE ARTICULOS POR MESES
**********************************
function fMovMeses()

Local cQry
Local cDato := "CORP012"

TEXT INTO cQry

SELECT mes,SUM(entradas) AS entradas,SUM(salidas) AS salidas FROM (
SELECT MONTH(MOV.o_fechas) AS mes,SUM(MOV.o_cansal) AS salidas,SUM(MOV.o_canent) AS entradas
FROM tbl_movi MOV WHERE MOV.o_articu='cDato' GROUP BY MONTH(MOV.o_fechas)
UNION
SELECT MONTH(FAC.mm_fechas) AS mes,SUM(FAC.mm_cansal) AS salidas,SUM(FAC.mm_canent) AS entradas
FROM tbl_mofa FAC WHERE FAC.mm_articu='cDato' GROUP BY MONTH(FAC.mm_fechas)
) MOV GROUP BY mes;

ENDTEXT

memoedit(cQry)
Return nil


Para este caso requiero reemplazar el valor de la variable cDato dentro de la cadena de texto.

De antemano gracias
Last edited by leandro on Thu Dec 12, 2019 2:50 pm, edited 1 time in total.
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1688
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Cadena extensa TEXT ENDTEXT

Postby nageswaragunupudi » Thu Dec 12, 2019 4:52 am

METHOD-1
Code: Select all  Expand view  RUN
function fMovMeses()

Local cQry
Local cDato := "CORP012"

TEXT INTO cQry
SELECT mes,SUM(entradas) AS entradas,SUM(salidas) AS salidas FROM (
 SELECT MONTH(MOV.o_fechas) AS mes,SUM(MOV.o_cansal) AS salidas,SUM(MOV.o_canent) AS entradas
 FROM tbl_movi MOV WHERE MOV.o_articu='cDato' GROUP BY MONTH(MOV.o_fechas)
 UNION
 SELECT MONTH(FAC.mm_fechas) AS mes,SUM(FAC.mm_cansal) AS salidas,SUM(FAC.mm_canent) AS entradas
 FROM tbl_mofa FAC WHERE FAC.mm_articu='cDato' GROUP BY MONTH(FAC.mm_fechas)
 ) MOV GROUP BY mes;
ENDTEXT

cQry := StrTran( cQry, "cDato", cDato )

memoedit(cQry)
 



METHOD-2
Code: Select all  Expand view  RUN
function fMovMeses()

Local cQry
//Local cDato := "CORP012"

PRIVATE cDato := "CORP012"


TEXT INTO cQry
SELECT mes,SUM(entradas) AS entradas,SUM(salidas) AS salidas FROM (
 SELECT MONTH(MOV.o_fechas) AS mes,SUM(MOV.o_cansal) AS salidas,SUM(MOV.o_canent) AS entradas
 FROM tbl_movi MOV WHERE MOV.o_articu='&cDato' GROUP BY MONTH(MOV.o_fechas)
 UNION
 SELECT MONTH(FAC.mm_fechas) AS mes,SUM(FAC.mm_cansal) AS salidas,SUM(FAC.mm_canent) AS entradas
 FROM tbl_mofa FAC WHERE FAC.mm_articu='&cDato' GROUP BY MONTH(FAC.mm_fechas)
 ) MOV GROUP BY mes;
ENDTEXT

MEMOEDIT( cQry )

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Cadena extensa TEXT ENDTEXT

Postby leandro » Thu Dec 12, 2019 2:49 pm

Excelente :D

Mr. Nages, como siempre muchísimas gracias.

Otra pregunta, por solo funciona con variables de tipo PRIVATE?
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1688
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Cadena extensa TEXT ENDTEXT - ( SOLUCIONADO )

Postby nageswaragunupudi » Thu Dec 12, 2019 3:25 pm

Otra pregunta, por solo funciona con variables de tipo PRIVATE?


If you want to use the macro expansion feature, i.e., &cVar, inside TEXT ... ENDTEXT, then the cVar has to be a PRIVATE or PUBLIC variable.

Otherwise, you can use a token like "<token>" and use StrTran(...) replacing that token with your value,

I gave both the approaches above.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Cadena extensa TEXT ENDTEXT - ( SOLUCIONADO )

Postby nageswaragunupudi » Thu Dec 12, 2019 3:44 pm

METHOD-3

Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local cQry

   cQry  := fMovMeses( "CORP012" )
   MEMOEDIT ( cQry )

return nil

function fMovMeses

   local cQry

   PARAMETERS cDato

TEXT INTO cQry
SELECT mes,SUM(entradas) AS entradas,SUM(salidas) AS salidas FROM (
 SELECT MONTH(MOV.o_fechas) AS mes,SUM(MOV.o_cansal) AS salidas,SUM(MOV.o_canent) AS entradas
 FROM tbl_movi MOV WHERE MOV.o_articu='&cDato' GROUP BY MONTH(MOV.o_fechas)
 UNION
 SELECT MONTH(FAC.mm_fechas) AS mes,SUM(FAC.mm_cansal) AS salidas,SUM(FAC.mm_canent) AS entradas
 FROM tbl_mofa FAC WHERE FAC.mm_articu='&cDato' GROUP BY MONTH(FAC.mm_fechas)
 ) MOV GROUP BY mes;
ENDTEXT

return cQry
 


Here we defined the FUNCTION with the Oldest Clipper syntax.

Instead of defining the function as:
Code: Select all  Expand view  RUN
function fMovMeses( cDato )


we declared the function like this:
Code: Select all  Expand view  RUN

FUNCTION fMovMeses
   // local declarations
   PARAMETERS cDato
 


These parameters are equivalent to PRIVATE.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

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

cron