码迷,mamicode.com
首页 > 其他好文 > 详细

根据funID,personID获取最新规划包项目相关信息

时间:2018-02-27 17:38:58      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:end   person   not   类型   tin   mit   name   ctp   dmi   


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

 

根据funID,personID获取最新规划包项目相关信息

标签:end   person   not   类型   tin   mit   name   ctp   dmi   

原文地址:https://www.cnblogs.com/liuqiyun/p/8479661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!