这个问题在这里已经有了答案:Setthevariableresult,fromquery(2个答案)关闭8年前。查询CREATEFUNCTIONAverageRateofProduct(p_toDatedatetime,p_productBatchIdlongtext)RETURNSdecimal(18,2)BEGINDeclarep_averageRatedecimal(18,2);if((SELECTIFNULL(sum(inwardQuantity),0)FROMtbl_StockPostingWHERE(date0)thensetp_averageRate=selectIFNU