create FUNCTION [dpm].[getValue](@processManageId varchar(32))
RETURNS @temptable table (carryDeptId varchar(32),carrydept varchar(100),investMoney float,productionValue float)
AS
begin
declare @carryDeptId varchar(32);
declare myCur cursor for ( select distinct carryDeptId from DPM_YW_Production_Value where processManageId = @processManageId )
open myCur
fetch next from myCur into @carryDeptId
while @@fetch_status = 0
begin
INSERT @temptable select * from (select top 1 carryDeptId,carrydept, investMoney as '总投资' ,productionValue as '产值' from DPM_YW_Production_Value where
carryDeptId=@carryDeptId order by createtime desc) a where (isnull(a.investMoney,0)!=0 or isnull(a.productionValue,0)!=0) and (isnull(a.investMoney,0)=0 or isnull(a.productionValue,0)!=0)
fetch next from myCur into @carryDeptId
end
close myCur
deallocate myCur
return
end