Eu montei a estrutura da seguinte forma:
SELECT ‘01’ EMPRESA , C.CT2_FILIAL AS FILIAL , ‘C’ AS TIPO,
C.CT2_CREDIT AS CONTA, C.CT2_VALOR VALOR, C.CT2_HIST HISTORICO
FROM CT2010 C
WHERE C.D_E_L_E_T_ <> ‘’
AND C.CT2_TPSALD = 1
AND C.CT2_CREDIT= ‘210100620’
and c.CT2_DATA BETWEEN ‘20170201’ and ‘20170228’
UNION ALL
SELECT ‘01’ EMPRESA ,C.CT2_FILIAL AS FILIAL , ‘D’ AS TIPO,
C.CT2_DEBITO AS CONTA, C.CT2_VALOR AS VALOR, C.CT2_HIST AS HISTORICO
FROM CT2010 C
WHERE C.D_E_L_E_T_ <> '’
AND C.CT2_TPSALD = 1
AND C.CT2_DEBITO = ‘210100620’
and c.CT2_DATA BETWEEN ‘20170201’ and ‘20170228’
UNION ALL
SELECT ‘01’ EMPRESA, ‘’ AS FILIAL, ‘SAT’ AS TIPO,
C7.CT7_CONTA AS CONTA, (SUM(C7.CT7_CREDIT) - SUM(C7.CT7_DEBITO)) AS VALOR, ‘’ AS HISTORICO
FROM CT7010 C7
WHERE C7.D_E_L_E_T_ <> ‘*’
AND C7.CT7_TPSALD = 1
AND C7.CT7_CONTA BETWEEN ‘210100620’ AND ‘210100620’
AND C7.CT7_DATA <= ‘20170228’
GROUP BY C7.CT7_CONTA
e minha ideia é substituir os valores por campos criados no filtro, ficando da seguinte forma:
SELECT ‘01’ EMPRESA , C.CT2_FILIAL AS FILIAL , ‘C’ AS TIPO,
C.CT2_CREDIT AS CONTA, C.CT2_VALOR VALOR, C.CT2_HIST HISTORICO
FROM CT2010 C
WHERE C.D_E_L_E_T_ <> ‘’
AND C.CT2_TPSALD = 1
AND C.CT2_CREDIT= ‘{v_conta}’
and c.CT2_DATA BETWEEN ‘20170201’ and ‘20170228’
UNION ALL
SELECT ‘01’ EMPRESA ,C.CT2_FILIAL AS FILIAL , ‘D’ AS TIPO,
C.CT2_DEBITO AS CONTA, C.CT2_VALOR AS VALOR, C.CT2_HIST AS HISTORICO
FROM CT2010 C
WHERE C.D_E_L_E_T_ <> '’
AND C.CT2_TPSALD = 1
AND C.CT2_DEBITO =’{v_conta}’
and c.CT2_DATA BETWEEN ‘20170201’ and ‘20170228’
UNION ALL
SELECT ‘01’ EMPRESA, ‘’ AS FILIAL, ‘SAT’ AS TIPO,
C7.CT7_CONTA AS CONTA, (SUM(C7.CT7_CREDIT) - SUM(C7.CT7_DEBITO)) AS VALOR, ‘’ AS HISTORICO
FROM CT7010 C7
WHERE C7.D_E_L_E_T_ <> ‘*’
AND C7.CT7_TPSALD = 1
AND C7.CT7_CONTA = ‘{v_conta}’
AND C7.CT7_DATA <= ‘20170228’
GROUP BY C7.CT7_CONTA
para isso estou criando campos em filtros
v_conta
v_dt_saldo
etc
Estou encontrando dificuldade no campo data, pois o formato interno do sql a data é tipo aaaammdd.
Criei o campo v_saldo tipo data e coloquei la na condição AND C7.CT7_DATA <= ‘{v_dt_saldo}’ e quando dou um echo no campo ele esta trazendo o formato 2017-02-28
Em eventos no filtro no onvalidate
estou usando
{v_dt_saldo} = sc_date_conv({v_dt_saldo},“aaaa-mm-dd”,“aaaammdd”);
porém não está funcionando.
alguem poderia me ajudar?