ExecSP:SQL= UPDATE FM_ZZPZD SET D022=(SELECT M026 FROM BS_F_KEMU WHERE M011=FM_ZZPZD.D011 AND M001=FM_ZZPZD.D001)
                                         ,D023=(SELECT M027 FROM BS_F_KEMU WHERE M011=FM_ZZPZD.D011 AND M001=FM_ZZPZD.D001)
WHERE D001='D02' AND EXISTS (SELECT * FROM BS_F_KEMU WHERE M011=FM_ZZPZD.D011 AND M001=FM_ZZPZD.D001) AND D002 IN
 (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');


UPDATE FM_ZZPZM SET M037=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M038=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M039=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M040=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M041=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M042=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';

UPDATE FM_ZZPZM SET M186=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M187=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M188=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M189=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M190=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M191=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';

UPDATE FM_ZZPZM SET M811=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M812=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M813=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M814=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M815=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';
UPDATE FM_ZZPZM SET M816=0 WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';

UPDATE FM_ZZPZM SET M037=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M038=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M039=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M040=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M041=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M042=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011);


UPDATE FM_ZZPZM SET M811=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M812=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M813=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M814=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M815=(SELECT SUM(D012) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M816=(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011);


UPDATE FM_ZZPZM SET M186=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1122' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M187=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2203' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M188=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1221' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M189=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2202' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M190=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT SUM(D013) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='1123' AND D019='' GROUP BY D011);

UPDATE FM_ZZPZM SET M191=(SELECT SUM(D012*(D022)+D013*(D023)) FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011)
WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
(SELECT * FROM FM_ZZPZD WHERE D001=FM_ZZPZM.M001 AND D002=FM_ZZPZM.M002 AND D011='2241' AND D019='' GROUP BY D011);

UPDATE  FM_ZZPZD SET D801=(SELECT M023 FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002)
                                            ,D802=(SELECT M014 FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002 AND M004>='2015-08-01' AND M004<='2015-08-31')
 WHERE D001='D02' AND ISNULL(D801,'')='' AND (D011='1122' OR D011='2203' OR D011='1221') AND D002
 IN (SELECT M002 FROM FM_ZZPZM WHERE ISNULL(M014,'')<>'') AND EXISTS 
(SELECT * FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002 AND M004>='2015-08-01' AND M004<='2015-08-31');

UPDATE  FM_ZZPZD SET D803=(SELECT M024 FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002 AND M004>='2015-08-01' AND M004<='2015-08-31')
                                            ,D804=(SELECT M015 FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002)
 WHERE D001='D02' AND ISNULL(D803,'')='' AND (D011='2202' OR D011='1123' OR D011='2241') AND D002
 IN (SELECT M002 FROM FM_ZZPZM WHERE ISNULL(M015,'')<>'') AND EXISTS 
(SELECT * FROM FM_ZZPZM WHERE M001='D02' AND M002=FM_ZZPZD.D002 AND M004>='2015-08-01' AND M004<='2015-08-31');

UPDATE FM_ZZPZD SET D801='' WHERE D001='D02' AND ISNULL(D802,'')='' AND ISNULL(D801,'')<>'' AND D002 IN (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');
UPDATE FM_ZZPZD SET D803='' WHERE D001='D02' AND ISNULL(D804,'')='' AND ISNULL(D803,'')<>'' AND D002 IN (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');
UPDATE FM_ZZPZD SET D805='' WHERE D001='D02' AND ISNULL(D806,'')='' AND ISNULL(D805,'')<>'' AND D002 IN (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');
UPDATE FM_ZZPZD SET D807='' WHERE D001='D02' AND ISNULL(D808,'')='' AND ISNULL(D807,'')<>'' AND D002 IN (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');
UPDATE FM_ZZPZD SET D809='' WHERE D001='D02' AND ISNULL(D810,'')='' AND ISNULL(D809,'')<>'' AND D002 IN (SELECT M002 FROM FM_ZZPZM WHERE M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31');

UPDATE FM_ZZPZM SET M023=(SELECT D801 FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D801,'')<>''
 AND (D011='1122' OR D011='2203' OR D011='1221') GROUP BY D801)
WHERE ISNULL(M014,'')=''  AND M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS
(SELECT * FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D801,'')<>''
 AND (D011='1122' OR D011='2203' OR D011='1221') GROUP BY D801);

UPDATE FM_ZZPZM SET M014=(SELECT D802 FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D802,'')<>''
 AND (D011='1122' OR D011='2203' OR D011='1221') GROUP BY D802)
WHERE ISNULL(M014,'')=''  AND M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS
 (SELECT * FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D802,'')<>''
 AND (D011='1122' OR D011='2203' OR D011='1221') GROUP BY D802);

UPDATE FM_ZZPZM SET M024=(SELECT D803 FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D803,'')<>''
 AND (D011='2202' OR D011='1123' OR D011='2241') GROUP BY D803)
WHERE ISNULL(M015,'')=''  AND M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS
 (SELECT * FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D803,'')<>''
 AND (D011='2202' OR D011='1123' OR D011='2241') GROUP BY D803);

UPDATE FM_ZZPZM SET M015=(SELECT D804 FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D804,'')<>''
 AND (D011='2202' OR D011='1123' OR D011='2241') GROUP BY D804)
WHERE ISNULL(M015,'')=''  AND M001='D02'  AND M004>='2015-08-01' AND M004<='2015-08-31' AND EXISTS 
 (SELECT D804 FROM FM_ZZPZD WHERE D001='D02' AND D002=FM_ZZPZM.M002  AND ISNULL(D804,'')<>''
 AND (D011='2202' OR D011='1123' OR D011='2241') GROUP BY D804);

UPDATE FM_ZZPZM SET M023=''
WHERE ISNULL(M014,'')=''  AND M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';

UPDATE FM_ZZPZM SET M024=''
WHERE ISNULL(M015,'')=''  AND M001='D02' AND M004>='2015-08-01' AND M004<='2015-08-31';


; error:在 SQL 语句结尾之后找到字符。
