1.定义:根据funID,personID获取最新规划包项目相关信息(code projecttype(阶段) Pname(code+name) projectID)
项目表
tbl_cfg_Project
规划包表
tbl_cfg_ProjectPackageHistory
项目表规划包映射表
tbl_cfg_PackageHistoryProjectMapping
计划版本
tbl_plan_RollMap
USE [ITMS] GO /****** Object: StoredProcedure [dbo].[usp_padmin_GetLimitingProject] Script Date: 2018/2/27 11:22:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE proc [dbo].[usp_padmin_GetLimitingProject] @FuncID uniqueidentifier,@PersonID uniqueidentifier as if exists(select * from tbl_padmin_DataScope where realprojectid = ‘00000000-0000-0000-0000-000000000001‘ and FuncID = @FuncID and PersonID = @PersonID) begin select a.code,a.projecttype, ‘ ‘+isnull(a.code,‘‘) + a.name PName, a.projectID into
#pro --最新规划包包含的所有项目的相关信息 code projecttype(阶段) Pname(code+name) projectID
from tbl_cfg_Project a , ( SELECT * FROM tbl_cfg_ProjectPackageHistory where RollMapID = (SELECT top 1 RollMapID FROM tbl_plan_RollMap order by StartDate desc , Code desc --最新规划包) ) b, tbl_cfg_PackageHistoryProjectMapping c where a.name is not null and b.PackageHistoryID = c.PackageHistoryID and c.ProjectID = a.ProjectID select * from ( ---获取项目中的类型 select distinct ty.* from ( select null code,-1 projecttype,‘未配置项目阶段‘ PName,newid() projectID union all select null code, id projecttype,name,newid() projectID from tblCommonDict where parentid = 58 ) ty join #pro on ty.projecttype = #pro.projecttype union all select * from #pro ) tbl order by projecttype, left(code,1),len(code),code,PName end else begin select a.code, a.projecttype, ‘ ‘+isnull(a.code,‘‘) + a.name PName, a.projectID into #pro1 from tbl_cfg_Project a join tbl_padmin_DataScope b on a.projectID = b.realprojectID join tbl_cfg_PackageHistoryProjectMapping c on c.ProjectID = a.ProjectID join ( SELECT * FROM tbl_cfg_ProjectPackageHistory where RollMapID = (SELECT top 1 RollMapID FROM tbl_plan_RollMap order by StartDate desc , Code desc) ) d on d.PackageHistoryID = c.PackageHistoryID where a.name is not null and b.FuncID = @FuncID and b.PersonID = @PersonID select * from ( ---获取项目中的类型 select distinct ty.* from ( select null code,-1 projecttype,‘未配置项目阶段‘ PName,newid() projectID union all select null code, id projecttype,name,newid() projectID from tblCommonDict where parentid = 58 ) ty join #pro1 on ty.projecttype = #pro1.projecttype union all select * from #pro1 ) tbl order by projecttype, left(code,1),len(code),code,PName end GO
2.使用:
CREATE TABLE #tmp(
code varchar(100),
projecttype varchar(100),
PName varchar(200),
ProjectID varchar(100)
)
INSERT INTO #tmp EXEC usp_padmin_GetLimitingProject ‘68093189-0dde-4ae2-b7ba-903ff77b66e6‘,‘E87B3AB0-6901-48C2-A30C-E643320BF275‘ --‘{1}‘,‘{2}‘
drop table #tmp