Я хочу выполнить этот запрос, но получаю ошибку:
error sql (1064): у вас есть ошибка в вашем синтаксисе SQL; проверьте руководство, соответствующее вашей версии сервера MariaDB, чтобы найти правильный синтаксис для использования рядом с '' в строке 97
Мой запрос:
CREATE PROCEDURE `ControlRecibos` ()
BEGIN
Select distinct T0.gestionescobra_tks_regional
,T0.gestionescobra_tks_cobrador
,T0.gestionescobra_tks_poliza
,T0.gestionescobra_tks_codigodecli
,T0.gestionescobra_tks_apellidoyno
,T0.gestionescobra_tks_formadepago
,T0.gestionescobra_tks_numerorecib
,T0.gestionescobra_tks_observacion
,T0.gestionescobra_tks_fechareport
,T0.gestionescobra_tks_montoprima
,T1.nocobradosmes_tks_montoprimama
,T1.nocobradosmes_tks_montoprima
From vtiger_gestionescobra T0 inner join
( Select *
From(
Select distinct gestionescobra_tks_cobrador,gestionescobra_tks_poliza,sum(gestionescobra_tks_montoprima) as MonCobrado
From vtiger_gestionescobra
where gestionescobra_tks_fechareport between '2020-03-20' and '2020-04-20' and
gestionescobra_tks_actividad = 'Cobranza' and gestionescobra_tks_numerorecib <>'' and gestionescobra_tks_notransacci <>'' and gestionescobra_tks_montoprima <> 0 and gestionescobra_tks_formadepago='M' group by gestionescobra_tks_cobrador,gestionescobra_tks_poliza )T0 inner Join (Select T0.nocobradosmes_tks_poliza,T0.nocobradosmes_tks_montoprimama,T0.nocobradosmes_tks_montoprima
From vtiger_nocobradosmes T0 inner join (
Select distinct nocobradosmes_tks_poliza,max(nocobradosmesid) as val
From vtiger_nocobradosmes
group by nocobradosmes_tks_poliza)
T1 ON T0.nocobradosmes_tks_poliza=T1.nocobradosmes_tks_poliza
where T0.nocobradosmesid=T1.val and nocobradosmes_tks_formadepago='Mensual')
T1 ON T0.gestionescobra_tks_poliza=T1.nocobradosmes_tks_poliza
where (nocobradosmes_tks_montoprima*50)/100>MonCobrado
Union
Select *
From(Select gestionescobra_tks_cobrador,gestionescobra_tks_poliza,sum(gestionescobra_tks_montoprima) as MonCobrado
From vtiger_gestionescobra
where gestionescobra_tks_fechareport between '2020-03-20' and '2020-04-20' and
gestionescobra_tks_actividad = 'Cobranza' and gestionescobra_tks_numerorecib <>'' and
gestionescobra_tks_notransacci <>'' and gestionescobra_tks_montoprima <> 0 and gestionescobra_tks_formadepago='T'
group by gestionescobra_tks_cobrador,gestionescobra_tks_poliza)
T0 inner Join
(Select T0.nocobradosmes_tks_poliza,T0.nocobradosmes_tks_montoprimama,T0.nocobradosmes_tks_montoprima
From vtiger_nocobradosmes T0 inner join (Select distinct nocobradosmes_tks_poliza,max(nocobradosmesid) as val
From vtiger_nocobradosmes
group by nocobradosmes_tks_poliza) T1 ON T0.nocobradosmes_tks_poliza=T1.nocobradosmes_tks_poliza
where T0.nocobradosmesid=T1.val and nocobradosmes_tks_formadepago='Trimestral' )
T1 ON T0.gestionescobra_tks_poliza=T1.nocobradosmes_tks_poliza
where (nocobradosmes_tks_montoprima)/3>MonCobrado
Union
Select *
From(Select gestionescobra_tks_cobrador,gestionescobra_tks_poliza,sum(gestionescobra_tks_montoprima) as MonCobrado
From vtiger_gestionescobra
where gestionescobra_tks_fechareport between '2020-03-20' and '2020-04-20' and
gestionescobra_tks_actividad = 'Cobranza' and gestionescobra_tks_numerorecib <>'' and
gestionescobra_tks_notransacci <>'' and gestionescobra_tks_montoprima <> 0 and gestionescobra_tks_formadepago='S'
group by gestionescobra_tks_cobrador,gestionescobra_tks_poliza)
T0 inner Join
(Select T0.nocobradosmes_tks_poliza,T0.nocobradosmes_tks_montoprimama,T0.nocobradosmes_tks_montoprima
From vtiger_nocobradosmes T0 inner join
(Select distinct nocobradosmes_tks_poliza,max(nocobradosmesid) as val
From vtiger_nocobradosmes
group by nocobradosmes_tks_poliza) T1 ON T0.nocobradosmes_tks_poliza=T1.nocobradosmes_tks_poliza
where T0.nocobradosmesid=T1.val and nocobradosmes_tks_formadepago='Semestral')
T1 ON T0.gestionescobra_tks_poliza=T1.nocobradosmes_tks_poliza
where (nocobradosmes_tks_montoprima)/6>MonCobrado
Union
Select *
From(Select gestionescobra_tks_cobrador,gestionescobra_tks_poliza,sum(gestionescobra_tks_montoprima) as MonCobrado
From vtiger_gestionescobra
where gestionescobra_tks_fechareport between '2020-03-20' and '2020-04-20'and
gestionescobra_tks_actividad = 'Cobranza' and gestionescobra_tks_numerorecib <>'' and
gestionescobra_tks_notransacci <>'' and gestionescobra_tks_montoprima <> 0 and gestionescobra_tks_formadepago='A'
group by gestionescobra_tks_cobrador,gestionescobra_tks_poliza)
T0 inner Join
(Select T0.nocobradosmes_tks_poliza,T0.nocobradosmes_tks_montoprimama,T0.nocobradosmes_tks_montoprima
From vtiger_nocobradosmes
T0 inner join (
Select distinct nocobradosmes_tks_poliza,max(nocobradosmesid) as val
From vtiger_nocobradosmes
group by nocobradosmes_tks_poliza
) T1 ON T0.nocobradosmes_tks_poliza=T1.nocobradosmes_tks_poliza
where T0.nocobradosmesid=T1.val and nocobradosmes_tks_formadepago='Anual'
)
T1 ON T0.gestionescobra_tks_poliza=T1.nocobradosmes_tks_poliza
where (nocobradosmes_tks_montoprima)/12>MonCobrado
)
T1 ON T0.gestionescobra_tks_cobrador=T1.gestionescobra_tks_cobrador
and T0.gestionescobra_tks_poliza=T1.gestionescobra_tks_poliza
where gestionescobra_tks_fechareport between '2020-03-20' and '2020-04-20' and
gestionescobra_tks_actividad = "Cobranza"
and gestionescobra_tks_numerorecib <>''
and gestionescobra_tks_notransacci <>''
and gestionescobra_tks_montoprima <> 0
ORDER BY 1,2;
END
MYSQL WorkBench показывает мне проблему только в 2 последних строках, например, "Отсутствует полуколона" в 2 и посторонний ввод найден в END
В чем проблема?