set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[sp_GetAllProVersions]
@nodeText varchar(50)
as
declare @Versions_Currenttable table
(
ProjectId int,
devVersion varchar(100),
devStart datetime,
devEnd datetime,
qaVersion varchar(100),
qaStart datetime,
qaEnd datetime,
proVersion varchar(100),
proStart datetime,
proEnd datetime
)
-- 声明
declare cur_titles cursor
for
--select a.*,ver.VersionNumber,convert(varchar(10),ver.StatusSince,120) as StatusSince,convert(varchar(10),ver.NextStatusBy,120) as NextStatusBy from
--(
-- select distinct D_V.ProjectID as ProjectId,max(D_V.AutoID) as D_AutoID,D_V.VersionCurrentStateID as D_VersionCS
-- from dbo.CurrentState as D_C
-- inner join Versions as D_V
-- on D_C.CurrentStateID=D_V.VersionCurrentStateID
-- group by D_V.ProjectID,D_V.VersionCurrentStateID,D_C.CurrentStateName
--) as a
--inner join dbo.Versions as ver
--on a.D_AutoId=ver.AutoID order by a.ProjectId
select a.ProjectId,ver.AutoID as D_AutoID,a.D_VersionCS,a.VersionNumber,convert(varchar(10),ver.StatusSince,120) as StatusSince,convert(varchar(10),ver.NextStatusBy,120) as NextStatusBy from
(
select distinct D_V.ProjectID as ProjectId,max(D_V.VersionNumber) as VersionNumber,D_V.VersionCurrentStateID as D_VersionCS
from dbo.CurrentState as D_C
left join Versions as D_V
on D_C.CurrentStateID=D_V.VersionCurrentStateID
group by D_V.ProjectID,D_V.VersionCurrentStateID,D_C.CurrentStateName
) as a
inner join dbo.Versions as ver
on a.ProjectId=ver.ProjectId and a.versionNumber=ver.versionNumber and a.D_VersionCS=ver.VersionCurrentStateID order by a.ProjectId
-- 打开
open cur_titles
declare @ProjectId int
declare @D_AutoID varchar(20)
declare @D_VersionCS varchar(20)
declare @VersionNumber varchar(20)
declare @StatusSince datetime
declare @NextStatusBy datetime
declare @Version datetime
FETCH cur_titles INTO @ProjectId,@D_AutoID,@D_VersionCS,@VersionNumber,@StatusSince,@NextStatusBy
WHILE @@FETCH_STATUS=0
BEGIN
if(@D_VersionCS=1)
if exists(select * from @Versions_Currenttable where ProjectId=@ProjectId)
begin
update @Versions_Currenttable set devVersion=@VersionNumber,devStart=@StatusSince,devEnd=@NextStatusBy where ProjectId=@ProjectId
End
else
begin
insert into @Versions_Currenttable(ProjectId,devVersion,devStart,devEnd)
values(@ProjectId,@VersionNumber,@StatusSince,@NextStatusBy)
end
if(@D_VersionCS=2)
if exists(select * from @Versions_Currenttable where ProjectId=@ProjectId)
begin
update @Versions_Currenttable set qaVersion=@VersionNumber,qaStart=@StatusSince,qaEnd=@NextStatusBy where ProjectId=@ProjectId
End
else
begin
insert into @Versions_Currenttable(ProjectId,qaVersion,qaStart,qaEnd)
values(@ProjectId,@VersionNumber,@StatusSince,@NextStatusBy)
end
if (@D_VersionCS=3)
if exists(select * from @Versions_Currenttable where ProjectId=@ProjectId)
begin
update @Versions_Currenttable set proVersion=@VersionNumber,proStart=@StatusSince,proEnd=@NextStatusBy where ProjectId=@ProjectId
End
else
begin
insert into @Versions_Currenttable(ProjectId,proVersion,proStart,proEnd)
values(@ProjectId,@VersionNumber,@StatusSince,@NextStatusBy)
End
FETCH next from cur_titles INTO @ProjectId,@D_AutoID,@D_VersionCS,@VersionNumber,@StatusSince,@NextStatusBy
END
-- 关闭
close cur_titles
-- 释放
deallocate cur_titles
select
st.[Text] as ProjectName
,Ver.devVersion,convert(varchar(10),Ver.devStart,120) as devStart,convert(varchar(10),Ver.devEnd,120) as devEnd
,Ver.qaVersion,convert(varchar(10),Ver.qaStart,120) as qaStart,convert(varchar(10),Ver.qaEnd,120)as qaEnd
,Ver.proVersion,convert(varchar(10),Ver.proStart,120) as proStart,convert(varchar(10),Ver.proEnd,120)as proEnd
from @Versions_Currenttable as Ver
inner join s_Tree as st
on st.NodeID=Ver.ProjectId
where st.parentid in
(
select nodeid from s_tree where [Text]=@nodeText
)
--exec sp_GetAllProVersions