|
strSQL="INSERT INTO tbl_TcIMP ( NumBase, ShpCount, ShpCountU, PrcSum, PrcSumU, WPS, WPSU) SELECT tbl_TS.shpConsInNum, Count(tbl_TS.shpid) AS Ord1, Sum(IIf([shpReal]=0,0,1)) AS OrdUch, Sum(tbl_TS.shpPrc) AS Prc, Sum(IIf([shpReal]=0,0,[shpPrc])) AS prcU, Sum(tbl_TS.shpWP) AS [WPS], Sum(IIf([shpReal]=0,0,[shpWP])) AS WPSU FROM tbl_TS GROUP BY tbl_TS.shpConsInNum HAVING tbl_TS.shpConsInNum<>''"
INSERT INTO tbl_TcIMP ( NumBase, ShpCount, ShpCountU, PrcSum, PrcSumU, WPS, WPSU ) SELECT tbl_TS.shpConsInNum, Count(tbl_TS.shpNumber) AS OrdCount, -Sum([shpID]/[shpID]*([shpReal]>0)) AS OrdUch, Sum(tbl_TS.shpPrc) AS [prcS], -Sum([shpPrc]*([shpReal]>0)) AS prcUch, Sum(tbl_TS.shpWP) AS [WPS], -Sum([shpWP]*([shpReal]>0)) AS WPSU FROM tbl_TS GROUP BY tbl_TS.shpConsInNum HAVING tbl_TS.shpConsInNum<>''"
1. CurrentProject.Connection.Execute strSQL 2. CurrentDB.Execute strSQL 3. DoCmd.RunSQL strSQL
CurrentDb.CreateQueryDef "sql_temp", strSQL DoCmd.OpenQuery "sql_temp" DoCmd.DeleteObject acQuery, "sql_temp"
http://www.sql.ru/forum/1257129/vypolnenie-zaprosa-zapushhennogo-raznymi-sposobami