SELECT idcliente_factura,
$0.00 AS credito_anterior,
$0.00 AS credito_acumulado,
$0.00 AS credito_mensual,
sum(case when fecha_factura<@fecha_inicial
then monto_factura
else $0.00 end) AS debito_anterior,
sum(case when fecha_factura<=@fecha_final
then monto_factura
else $0.00 end) AS debito_acumulado,
sum(case when fecha_factura>=@fecha_inicial and fecha_factura<=@fecha_final
then monto_factura
else $0.00 end) AS DEBITO_mensual,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
space(3) as idtipomovimiento_movimientocxc,
0 as iddocumento_movimientocxc,
idtype_factura
into #factura_movi
from ctacobrar_factura
where idmodulo_factura=@idmodulo
and IDSUCURSAL_factura>=@IDSUCURSAL1
and IDSUCURSAL_factura<=@IDSUCURSAL2
AND ESTATUS_FACTURA=1
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,
tipofactura_factura,idfactura_factura
union
SELECT idcliente_factura,
sum(case when fecha_movimientocxc<@fecha_inicial and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end) AS credito_anterior,
sum(case when fecha_movimientocxc<=@fecha_final and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end ) AS credito_acumulado,
sum(case when fecha_movimientocxc>=@fecha_inicial and fecha_movimientocxc<=@fecha_final
and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end ) AS credito_mensual,
sum(case when fecha_movimientocxc<@fecha_inicial and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS debito_anterior,
sum(case when fecha_movimientocxc<=@fecha_final and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS debito_acumulado,
sum(case when fecha_movimientocxc>=@fecha_inicial and fecha_movimientocxc<=@fecha_final
and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS DEBITO_mensual,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
from ctacobrar_factura
join ctacobrar_movimiento
on idcliente_factura = idcliente_movimientocxc
and idmodulo_factura=@idmodulo
and IDSUCURSAL_factura>=@IDSUCURSAL1
and IDSUCURSAL_factura<=@IDSUCURSAL2
AND ESTATUS_FACTURA=1
and idfactura_factura = idfactura_movimientocxc
and tipofactura_factura = tipofactura_movimientocxc
AND ESTATUS_MOVIMIENTOCXC = 1
and idtype_factura = @idtype1
and idtype_movimientocxc = @idtype1
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,
tipofactura_factura,idfactura_factura,idtipomovimiento_movimientocxc,
iddocumento_movimientocxc
order by idcliente_factura
SELECT max(idcliente_factura) as idcliente_factura,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(debito_acumulado)-SUM(credito_acumulado) AS balance_actual,
SUM(debito_anterior)-SUM(credito_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
into #balance_factura
from #factura_movi
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,tipofactura_factura,idfactura_factura
SELECT max(idcliente_factura) as idcliente_factura,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(balance_actual) AS balance_actual,
SUM(balance_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
into #auxiliar
from #balance_factura
group by idtype_factura,idcliente_factura
having (sum(balance_anterior)<>0 or
sum(DEBITO_mensual)<>0 or
sum(credito_mensual)<>0 or
SUM(balance_actual)<>0)
order by idcliente_factura
SELECT max(idcliente_factura) as idcliente_factura,
max(idreferencia_cliente) as idreferencia_cliente,
max(rtrim(nombre_cliente)+' '+rtrim(apellido1_cliente)+' '+rtrim(apellido2_cliente)) as nombre_cliente,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(balance_actual) AS balance_actual,
SUM(balance_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
max(idtype_factura) aS idtype_factura,
max(descripcion_tipocxc) as descripcion_tipocxc,
max(IDtipocxc_cliente) as IDtipocxc_cliente
from #auxiliar
join ctacobrar_cliente
on idcliente_cliente=idcliente_factura
and IDtipocxc_cliente>=@IDtipocxc1
and IDtipocxc_cliente<=@IDtipocxc2
and idtype_factura>=@idtype1
and idtype_factura<=@idtype2
join ctacobrar_tipocxc
on IDtipocxc_cliente=idtipocxc_tipocxc
group by iDtipocxc_cliente,idcliente_factura
order by iDtipocxc_cliente,idcliente_factura
GO
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is currently a limitation in how long statements are supported in the converter, this seems to be the problem in your case. I have a new version to fix this, send me a mail at erik {at} wetterberg {dot} com and I will mail it to you. If it works OK I will make it available for download.
Regards
Erik
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Welcome to Help
When a try to convert an store procedure windows give me a error.
This is the store procedure:
CREATE PROCEDURE cxc_ctacobrar_Auxiliar_estandar_add
@fecha_inicial smalldatetime,
@fecha_final smalldatetime,
@idmodulo smallint,
@idtype1 smallint,
@IDtipocxc1 smallint,
@IDtipocxc2 smallint,
@IDSUCURSAL1 smallint,
@IDSUCURSAL2 smallint,
@idtype2 smallint
as
set nocount on
SELECT idcliente_factura,
$0.00 AS credito_anterior,
$0.00 AS credito_acumulado,
$0.00 AS credito_mensual,
sum(case when fecha_factura<@fecha_inicial
then monto_factura
else $0.00 end) AS debito_anterior,
sum(case when fecha_factura<=@fecha_final
then monto_factura
else $0.00 end) AS debito_acumulado,
sum(case when fecha_factura>=@fecha_inicial and fecha_factura<=@fecha_final
then monto_factura
else $0.00 end) AS DEBITO_mensual,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
space(3) as idtipomovimiento_movimientocxc,
0 as iddocumento_movimientocxc,
idtype_factura
into #factura_movi
from ctacobrar_factura
where idmodulo_factura=@idmodulo
and IDSUCURSAL_factura>=@IDSUCURSAL1
and IDSUCURSAL_factura<=@IDSUCURSAL2
AND ESTATUS_FACTURA=1
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,
tipofactura_factura,idfactura_factura
union
SELECT idcliente_factura,
sum(case when fecha_movimientocxc<@fecha_inicial and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end) AS credito_anterior,
sum(case when fecha_movimientocxc<=@fecha_final and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end ) AS credito_acumulado,
sum(case when fecha_movimientocxc>=@fecha_inicial and fecha_movimientocxc<=@fecha_final
and idcategoria_movimientocxc=2
then monto_movimientocxc
else $0.00 end ) AS credito_mensual,
sum(case when fecha_movimientocxc<@fecha_inicial and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS debito_anterior,
sum(case when fecha_movimientocxc<=@fecha_final and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS debito_acumulado,
sum(case when fecha_movimientocxc>=@fecha_inicial and fecha_movimientocxc<=@fecha_final
and idcategoria_movimientocxc=1
then monto_movimientocxc
else $0.00 end ) AS DEBITO_mensual,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
from ctacobrar_factura
join ctacobrar_movimiento
on idcliente_factura = idcliente_movimientocxc
and idmodulo_factura=@idmodulo
and IDSUCURSAL_factura>=@IDSUCURSAL1
and IDSUCURSAL_factura<=@IDSUCURSAL2
AND ESTATUS_FACTURA=1
and idfactura_factura = idfactura_movimientocxc
and tipofactura_factura = tipofactura_movimientocxc
AND ESTATUS_MOVIMIENTOCXC = 1
and idtype_factura = @idtype1
and idtype_movimientocxc = @idtype1
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,
tipofactura_factura,idfactura_factura,idtipomovimiento_movimientocxc,
iddocumento_movimientocxc
order by idcliente_factura
SELECT max(idcliente_factura) as idcliente_factura,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(debito_acumulado)-SUM(credito_acumulado) AS balance_actual,
SUM(debito_anterior)-SUM(credito_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
into #balance_factura
from #factura_movi
group by idtype_factura,IDSUCURSAL_factura,idcliente_factura,tipofactura_factura,idfactura_factura
SELECT max(idcliente_factura) as idcliente_factura,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(balance_actual) AS balance_actual,
SUM(balance_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
idtype_factura
into #auxiliar
from #balance_factura
group by idtype_factura,idcliente_factura
having (sum(balance_anterior)<>0 or
sum(DEBITO_mensual)<>0 or
sum(credito_mensual)<>0 or
SUM(balance_actual)<>0)
order by idcliente_factura
SELECT max(idcliente_factura) as idcliente_factura,
max(idreferencia_cliente) as idreferencia_cliente,
max(rtrim(nombre_cliente)+' '+rtrim(apellido1_cliente)+' '+rtrim(apellido2_cliente)) as nombre_cliente,
sum(credito_anterior) AS credito_anterior,
sum(credito_acumulado) AS credito_acumulado,
sum(credito_mensual) AS credito_mensual,
sum(debito_anterior) AS debito_anterior,
sum(debito_acumulado) as debito_acumulado,
sum(DEBITO_mensual) AS DEBITO_mensual,
SUM(balance_actual) AS balance_actual,
SUM(balance_anterior) AS balance_anterior,
max(IDSUCURSAL_factura) as IDSUCURSAL_factura,
max(idtipocxc_factura) as idtipocxc_factura,
max(tipofactura_factura) as tipofactura_factura,
max(idfactura_factura) as idfactura_factura,
max(idtipomovimiento_movimientocxc) as idtipomovimiento_movimientocxc,
max(iddocumento_movimientocxc) as iddocumento_movimientocxc,
max(idtype_factura) aS idtype_factura,
max(descripcion_tipocxc) as descripcion_tipocxc,
max(IDtipocxc_cliente) as IDtipocxc_cliente
from #auxiliar
join ctacobrar_cliente
on idcliente_cliente=idcliente_factura
and IDtipocxc_cliente>=@IDtipocxc1
and IDtipocxc_cliente<=@IDtipocxc2
and idtype_factura>=@idtype1
and idtype_factura<=@idtype2
join ctacobrar_tipocxc
on IDtipocxc_cliente=idtipocxc_tipocxc
group by iDtipocxc_cliente,idcliente_factura
order by iDtipocxc_cliente,idcliente_factura
GO
There is currently a limitation in how long statements are supported in the converter, this seems to be the problem in your case. I have a new version to fix this, send me a mail at erik {at} wetterberg {dot} com and I will mail it to you. If it works OK I will make it available for download.
Regards
Erik