Stringsql="select TOP 20 a.nGoodsID GoodsID, g.sGoodsNO GoodsNO, g.sGoodsDesc GoodsName, acg.nSalePrice Price, acg.sSpec Spec, acg.sUnit Unit, acg.nMinSaleQty MinQty, "
+" acg.nSaleUnits SaleUnit, acg.nMarketPrice MarketPrice, sum(a.nSaleQty) SaleQty from tAgentGoodsDailyOnline a join tGoods g on a.nGoodsID = g.nGoodsID "
+" join tAgentContractGoods acg on a.sAgentContractNO = acg.sAgentContractNO and a.nGoodsID = acg.nGoodsID ";
sql+=" ,tUserOrg tu, tUserAgent ua where acg.sOrgNO = '"+orgNO+"' and acg.sOrgNO = tu.sOrgNO and tu.sUserNO = '"+userNO+"' and tu.nTag&1 = 0"
+" and acg.nAgentID = ua.nAgentID and ua.sUserNO = '"+userNO+"' and ua.nTag&1 = 0 and a.dTradeDate >= '"+beginDate+"' and a.dTradeDate < '"+endDate+"' ";
}else{
sql+=" where acg.sOrgNO = '"+orgNO+"' and a.dTradeDate >= '"+beginDate+"' and a.dTradeDate < '"+endDate+"'";
}
sql+=" group by a.nGoodsID, g.sGoodsNO, g.sGoodsDesc, acg.nSalePrice, acg.sSpec, acg.sUnit, acg.nMinSaleQty, acg.nSaleUnits, acg.nMarketPrice, acg.sMarketUnit order by "