Create function Fn_GetJobListByPID--创建自定义函数获取指定兼职参与的所有项目编号及项目数量 ( @ParttimerID int ) returns @t table(Jobs varchar(5000),ParttimerID int,TotalCount int) as begin declare @sql varchar(5000),@TotalCount int set @sql='' set @TotalCount=0 select @sql=@sql+j.JobNo+'-'+j.JobWave+' ',@TotalCount=@TotalCount+1 from ONJB_JobApplication a,ONJB_Jobs j where a.ParttimerID=@ParttimerID and a.Result='V' and a.JobID=j.JobID insert @t values(@sql,@ParttimerID,@TotalCount) return end
引用
复制代码 代码如下:
--........................... --做过项目 left join (select Jobs,ParttimerID,TotalCount From Fn_GetJobListByPID(@ParttimerID)) as j1 on p.ParttimerID=j1.ParttimerID --在做项目 left join (select CurJobs,ParttimerID,CurCount From Fn_GetCurJobsByPID(@ParttimerID)) as j2 on p.ParttimerID=j2.ParttimerID where p.ParttimerID=@ParttimerID