您的 SQL 语法有误;检查与您的MySQL服务器版本相对应的手册,了解在第1行的')'附近使用的正确语法



我在程序中调用的过程出现错误。请帮我解决这个问题,这让我很困惑。我收到这样的消息:"您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解在第1行

附近使用')'的正确语法。

这是程序的源代码:

    BEGIN
DECLARE tampung  VARCHAR(1000);
DROP TEMPORARY TABLE IF EXISTS xxx_sensusdaftar_rajal;
SET @tabel = 'create TEMPORARY table xxx_sensusdaftar_rajal( tglreg date, shift1 int, pasienbaru int, kdpoly int, P int, L int, poly_rj1 int, poly_rj2 int, poly_rj3 int, poly_rj4 int, polyrujukan int, ';
select group_concat(concat('carabayar_kd',kode,' int') separator ', ') into tampung from m_carabayar order by kode;
set @tabel = concat(@tabel,tampung,')');
PREPARE stmt1 FROM @tabel;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
set @insert1 = "insert into xxx_sensusdaftar_rajal
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,";
set tampung = '';
select group_concat(concat('cast(sum(a.kdcarabayar/',kode,'*(1-abs(sign(a.kdcarabayar-',kode,')))) as UNSIGNED ) as carabayar_kd',kode) separator ', ') into tampung from m_carabayar order by kode;
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=1 and a.nomr=b.nomr and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=2 and a.nomr=b.nomr and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=3 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=4 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=5 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=6 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=7 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=8 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=28 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=29 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=30 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=9 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=10 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly
union
select a.tglreg,a.shift,a.pasienbaru,a.kdpoly,
sum( if(b.jeniskelamin='P',1, null)) as P,
sum(if(b.jeniskelamin='L', 1, null ))as L,
cast(sum(a.kdrujuk*(1-abs(sign(a.kdrujuk-1)))) as UNSIGNED ) as poly_rujuk_kd1,
cast(sum(a.kdrujuk/2*(1-abs(sign(a.kdrujuk-2)))) as UNSIGNED ) as poly_rujuk_kd2,
cast(sum(a.kdrujuk/3*(1-abs(sign(a.kdrujuk-3)))) as UNSIGNED ) as poly_rujuk_kd3,
cast(sum(a.kdrujuk/4*(1-abs(sign(a.kdrujuk-4)))) as UNSIGNED ) as poly_rujuk_kd4,
cast(sum(kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as poli_kd11,");
set @insert1 = concat(@insert1,tampung," FROM t_pendaftaran a , m_pasien b
where a.kdpoly=11 and a.nomr=b.nomr  and tglreg between '",inTANGGAL,"' and '",inTANGGAL2,"' GROUP BY a.tglreg,a.pasienbaru,a.kdpoly;");
PREPARE stmt2 FROM @insert1;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
DROP TEMPORARY TABLE IF EXISTS xxx_sensusdaftar_rajal2;
SET @tabel2 = 'create TEMPORARY table  xxx_sensusdaftar_rajal2(
tglreg date,
shift1 int,
pasienbaru varchar(10),
P int,
L int,
poli1_rj1 int,
poli2_rj1 int,
poli3_rj1 int,
poli4_rj1 int,
poli5_rj1 int,
poli6_rj1 int,
poli7_rj1 int,
poli8_rj1 int,
poli9_rj1 int,
poli10_rj1 int,
poli28_rj1 int,
poli29_rj1 int,
poli30_rj1 int,
poli1_rj2 int,
poli2_rj2 int,
poli3_rj2 int,
poli4_rj2 int,
poli5_rj2 int,
poli6_rj2 int,
poli7_rj2 int,
poli8_rj2 int,
poli9_rj2 int,
poli10_rj2 int,
poli28_rj2 int,
poli29_rj2 int,
poli30_rj2 int,
poli1_rj3 int,
poli2_rj3 int,
poli3_rj3 int,
poli4_rj3 int,
poli5_rj3 int,
poli6_rj3 int,
poli7_rj3 int,
poli8_rj3 int,
poli9_rj3 int,
poli10_rj3 int,
poli28_rj3 int,
poli29_rj3 int,
poli30_rj3 int,
poli1_rj4 int,
poli2_rj4 int,
poli3_rj4 int,
poli4_rj4 int,
poli5_rj4 int,
poli6_rj4 int,
poli7_rj4 int,
poli8_rj4 int,
poli9_rj4 int,
poli10_rj4 int,
poli28_rj4 int,
poli29_rj4 int,
poli30_rj4 int,
rujukan int,';
set tampung = '';
select group_concat(concat('crbyr',kode,' int') separator ', ') into tampung from m_carabayar order by kode;
set @tabel2 = concat(@tabel2,tampung,', total int);');
PREPARE stmt3 FROM @tabel2;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
set @insert2 = "insert into xxx_sensusdaftar_rajal2
select tglreg, a.shift1,case a.pasienbaru when 0 then 'LAMA'  when 1 then 'BARU' end as pasienbaru,
sum(P) as P,
sum(L) as L,
cast(sum(poly_rj1*kdpoly*(1-abs(sign(kdpoly-1)))) as UNSIGNED ) as poli1_rj1,
cast(sum(poly_rj1*kdpoly/2*(1-abs(sign(kdpoly-2)))) as UNSIGNED ) as poli2_rj1,
cast(sum(poly_rj1*kdpoly/3*(1-abs(sign(kdpoly-3)))) as UNSIGNED ) as poli3_rj1, 
cast(sum(poly_rj1*kdpoly/4*(1-abs(sign(kdpoly-4)))) as UNSIGNED ) as poli4_rj1,
cast(sum(poly_rj1*kdpoly/5*(1-abs(sign(kdpoly-5)))) as UNSIGNED ) as poli5_rj1,
cast(sum(poly_rj1*kdpoly/6*(1-abs(sign(kdpoly-6)))) as UNSIGNED ) as poli6_rj1,
cast(sum(poly_rj1*kdpoly/7*(1-abs(sign(kdpoly-7)))) as UNSIGNED ) as poli7_rj1,
cast(sum(poly_rj1*kdpoly/8*(1-abs(sign(kdpoly-8)))) as UNSIGNED ) as poli8_rj1,
cast(sum(poly_rj1*kdpoly/9*(1-abs(sign(kdpoly-9)))) as UNSIGNED ) as poli9_rj1,
cast(sum(poly_rj1*kdpoly/10*(1-abs(sign(kdpoly-10)))) as UNSIGNED ) as poli10_rj1,                        
cast(sum(poly_rj1*kdpoly/28*(1-abs(sign(kdpoly-28)))) as UNSIGNED ) as poli28_rj1,
cast(sum(poly_rj1*kdpoly/29*(1-abs(sign(kdpoly-29)))) as UNSIGNED ) as poli29_rj1,
cast(sum(poly_rj1*kdpoly/30*(1-abs(sign(kdpoly-30)))) as UNSIGNED ) as poli30_rj1,
cast(sum(poly_rj2*kdpoly*(1-abs(sign(kdpoly-1)))) as UNSIGNED ) as poli1_rj2,
cast(sum(poly_rj2*kdpoly/2*(1-abs(sign(kdpoly-2)))) as UNSIGNED ) as poli2_rj2,
cast(sum(poly_rj2*kdpoly/3*(1-abs(sign(kdpoly-3)))) as UNSIGNED ) as poli3_rj2, 
cast(sum(poly_rj2*kdpoly/4*(1-abs(sign(kdpoly-4)))) as UNSIGNED ) as poli4_rj2,
cast(sum(poly_rj2*kdpoly/5*(1-abs(sign(kdpoly-5)))) as UNSIGNED ) as poli5_rj2,
cast(sum(poly_rj2*kdpoly/6*(1-abs(sign(kdpoly-6)))) as UNSIGNED ) as poli6_rj2,
cast(sum(poly_rj2*kdpoly/7*(1-abs(sign(kdpoly-7)))) as UNSIGNED ) as poli7_rj2,
cast(sum(poly_rj2*kdpoly/8*(1-abs(sign(kdpoly-8)))) as UNSIGNED ) as poli8_rj2,
cast(sum(poly_rj2*kdpoly/9*(1-abs(sign(kdpoly-9)))) as UNSIGNED ) as poli9_rj2,
cast(sum(poly_rj2*kdpoly/10*(1-abs(sign(kdpoly-10)))) as UNSIGNED ) as poli10_rj2,
cast(sum(poly_rj2*kdpoly/28*(1-abs(sign(kdpoly-28)))) as UNSIGNED ) as poli28_rj2,
cast(sum(poly_rj2*kdpoly/29*(1-abs(sign(kdpoly-29)))) as UNSIGNED ) as poli29_rj2,
cast(sum(poly_rj2*kdpoly/30*(1-abs(sign(kdpoly-30)))) as UNSIGNED ) as poli30_rj2,
cast(sum(poly_rj3*kdpoly*(1-abs(sign(kdpoly-1)))) as UNSIGNED ) as poli1_rj3,
cast(sum(poly_rj3*kdpoly/2*(1-abs(sign(kdpoly-2)))) as UNSIGNED ) as poli2_rj3,
cast(sum(poly_rj3*kdpoly/3*(1-abs(sign(kdpoly-3)))) as UNSIGNED ) as poli3_rj3, 
cast(sum(poly_rj3*kdpoly/4*(1-abs(sign(kdpoly-4)))) as UNSIGNED ) as poli4_rj3,
cast(sum(poly_rj3*kdpoly/5*(1-abs(sign(kdpoly-5)))) as UNSIGNED ) as poli5_rj3,
cast(sum(poly_rj3*kdpoly/6*(1-abs(sign(kdpoly-6)))) as UNSIGNED ) as poli6_rj3,
cast(sum(poly_rj3*kdpoly/7*(1-abs(sign(kdpoly-7)))) as UNSIGNED ) as poli7_rj3,
cast(sum(poly_rj3*kdpoly/8*(1-abs(sign(kdpoly-8)))) as UNSIGNED ) as poli8_rj3,
cast(sum(poly_rj3*kdpoly/9*(1-abs(sign(kdpoly-9)))) as UNSIGNED ) as poli9_rj3,
cast(sum(poly_rj3*kdpoly/10*(1-abs(sign(kdpoly-10)))) as UNSIGNED ) as poli10_rj3,
cast(sum(poly_rj3*kdpoly/28*(1-abs(sign(kdpoly-28)))) as UNSIGNED ) as poli28_rj3,
cast(sum(poly_rj3*kdpoly/29*(1-abs(sign(kdpoly-29)))) as UNSIGNED ) as poli29_rj3,
cast(sum(poly_rj3*kdpoly/30*(1-abs(sign(kdpoly-30)))) as UNSIGNED ) as poli30_rj3,
cast(sum(poly_rj4*kdpoly*(1-abs(sign(kdpoly-1)))) as UNSIGNED ) as poli1_rj4,
cast(sum(poly_rj4*kdpoly/2*(1-abs(sign(kdpoly-2)))) as UNSIGNED ) as poli2_rj4,
cast(sum(poly_rj4*kdpoly/3*(1-abs(sign(kdpoly-3)))) as UNSIGNED ) as poli3_rj4, 
cast(sum(poly_rj4*kdpoly/4*(1-abs(sign(kdpoly-4)))) as UNSIGNED ) as poli4_rj4,
cast(sum(poly_rj4*kdpoly/5*(1-abs(sign(kdpoly-5)))) as UNSIGNED ) as poli5_rj4,
cast(sum(poly_rj4*kdpoly/6*(1-abs(sign(kdpoly-6)))) as UNSIGNED ) as poli6_rj4,
cast(sum(poly_rj4*kdpoly/7*(1-abs(sign(kdpoly-7)))) as UNSIGNED ) as poli7_rj4,
cast(sum(poly_rj4*kdpoly/8*(1-abs(sign(kdpoly-8)))) as UNSIGNED ) as poli8_rj4,
cast(sum(poly_rj4*kdpoly/9*(1-abs(sign(kdpoly-9)))) as UNSIGNED ) as poli9_rj4,
cast(sum(poly_rj4*kdpoly/10*(1-abs(sign(kdpoly-10)))) as UNSIGNED ) as poli10_rj4,
cast(sum(poly_rj4*kdpoly/28*(1-abs(sign(kdpoly-28)))) as UNSIGNED ) as poli28_rj4,
cast(sum(poly_rj4*kdpoly/29*(1-abs(sign(kdpoly-29)))) as UNSIGNED ) as poli29_rj4,
cast(sum(poly_rj4*kdpoly/30*(1-abs(sign(kdpoly-30)))) as UNSIGNED ) as poli30_rj4,
cast(sum(poly_rj1*kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) +
cast(sum(poly_rj2*kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) +
cast(sum(poly_rj3*kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) +
cast(sum(poly_rj4*kdpoly/11*(1-abs(sign(kdpoly-11)))) as UNSIGNED ) as rujukan,";
set tampung = '';
select group_concat(concat('sum(carabayar_kd',kode,') as crbyr',kode) separator ', ') into tampung from m_carabayar order by kode;
set @insert2 = concat(@insert2,tampung,', ');
set tampung = '';
select group_concat(concat('sum(carabayar_kd',kode,')') separator '+') into tampung from m_carabayar order by kode;
set @insert2 = concat(@insert2,tampung," as total
FROM xxx_sensusdaftar_rajal a GROUP BY tglreg, a.pasienbaru
ORDER BY tglreg DESC;");
PREPARE stmt4 FROM @insert2;
EXECUTE stmt4;
DEALLOCATE PREPARE stmt4;
set @select = "select shift1, pasienbaru,
sum(P) as P,
sum(L) as L,
sum(poli1_rj1) as poli1_rj1,
sum(poli2_rj1) as poli2_rj1,
sum(poli3_rj1) as poli3_rj1,
sum(poli4_rj1) as poli4_rj1,
sum(poli5_rj1) as poli5_rj1,
sum(poli6_rj1) as poli6_rj1,
sum(poli7_rj1) as poli7_rj1,
sum(poli8_rj1) as poli8_rj1,
sum(poli9_rj1) as poli9_rj1,
sum(poli10_rj1) as poli10_rj1,
sum(poli28_rj1) as poli28_rj1,
sum(poli29_rj1) as poli29_rj1,
sum(poli30_rj1) as poli30_rj1,
sum(poli1_rj2) as poli1_rj2,
sum(poli2_rj2) as poli2_rj2,
sum(poli3_rj2) as poli3_rj2,
sum(poli4_rj2) as poli4_rj2,
sum(poli5_rj2) as poli5_rj2,
sum(poli6_rj2) as poli6_rj2,
sum(poli7_rj2) as poli7_rj2,
sum(poli8_rj2) as poli8_rj2,
sum(poli9_rj2) as poli9_rj2,
sum(poli10_rj2) as poli10_rj2,
sum(poli28_rj2) as poli28_rj2,
sum(poli29_rj2) as poli29_rj2,
sum(poli30_rj2) as poli30_rj2,
sum(poli1_rj3) as poli1_rj3,
sum(poli2_rj3) as poli2_rj3,
sum(poli3_rj3) as poli3_rj3,
sum(poli4_rj3) as poli4_rj3,
sum(poli5_rj3) as poli5_rj3,
sum(poli6_rj3) as poli6_rj3,
sum(poli7_rj3) as poli7_rj3,
sum(poli8_rj3) as poli8_rj3,
sum(poli9_rj3) as poli9_rj3,
sum(poli10_rj3) as poli10_rj3,
sum(poli28_rj3) as poli28_rj3,
sum(poli29_rj3) as poli29_rj3,
sum(poli30_rj3) as poli30_rj3,
sum(poli1_rj4) as poli1_rj4,
sum(poli2_rj4) as poli2_rj4,
sum(poli3_rj4) as poli3_rj4,
sum(poli4_rj4) as poli4_rj4,
sum(poli5_rj4) as poli5_rj4,
sum(poli6_rj4) as poli6_rj4,
sum(poli7_rj4) as poli7_rj4,
sum(poli8_rj4) as poli8_rj4,
sum(poli9_rj4) as poli9_rj4,
sum(poli10_rj4) as poli10_rj4,
sum(poli28_rj4) as poli28_rj4,
sum(poli29_rj4) as poli29_rj4,
sum(poli30_rj4) as poli30_rj4,
sum(rujukan) as rujukan,";
set tampung = '';
select group_concat(concat('sum(crbyr',kode,') as crbyr',kode) separator ', ') into tampung from m_carabayar order by kode;
set @select = concat(@select,tampung,', sum(total) as total from xxx_sensusdaftar_rajal2 group by pasienbaru;');
PREPARE stmt5 FROM @select;
EXECUTE stmt5;
DEALLOCATE PREPARE stmt5;
  END

我发誓我刚刚在我的系统上测试了这个。与剪切和粘贴整个内容不同的是,只需将

内的内容全部括起来
DELIMITER $$
create procedure blahblah789()
(ALL OF YOUR STUFF)
$$
DELIMITER ;

它工作,意思是,没有1064语法错误。如果我运行它,很明显我不会有这些表。

需要用分隔。试一试

手册页使用分隔符与MySqlScript

相关内容

  • 没有找到相关文章

最新更新