2017-11-09 3 views
1

こんにちは、以下の支援を求めています。バグのライフサイクル中にバグが発生したときを区別するためのレポートを作成しています。私たちの現在のプロセスは、以下の状態を経由するバグがあります。TfsWarehouse DBの状態変化が最初に発生したことを特定しました

[新規]> [コミット]> [進行中のビルド>>>

を行い、障害がバグを解決しましたから行くか発生した場合の解決:

はまた再び失敗する可能性のビルド>解決済み>

を完了>進行中>失敗しました。 TfsWarehouseは、これらの変更をリビジョンとして記録します。私が抱えている問題は、バグに加えられた変更が改訂としてカウントされることです。これは、タイトル、説明などの別のフィールドへの変更である可能性があります。すべてのリビジョンはテーブルにレコードを作成します。同じPreviousStateSystem_Stateのエントリを持つ複数のレコード私は、状態変化の最初のインスタンスを区別し、重複は下記を参照排除するためにクエリを記述することができた:されないことCTEを使用し、基本的にはどのような状態の最初のインスタンスに1を加算して上記

WITH myTable (WorkItem, PreviousState, ChangedDate, ChangedBy, ID, Title, CurrentState, RevisionNo, Reason, CreatedDate, toNew, toCommited, toIP, toBuild, toResolved, toDone, toFailed, FailedtoIP) 

AS (
SELECT 
     [WorkItem] 
     ,[PreviousState] 
     ,[System_ChangedDate] 
     ,dp.Name as 'Changed By' 
     ,[System_Id] 
     ,[System_Title] 
     ,[System_State] 
     ,[System_Rev] 
     ,[System_Reason] 
     ,[System_CreatedDate] 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState IS NULL AND System_State = 'New' then 1 else 2 end), System_ChangedDate asc) as newseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'New' AND System_State = 'Committed' then 1 else 2 end), System_ChangedDate asc) as ntocomseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'Committed' AND System_State = 'In Progress' then 1 else 2 end), System_ChangedDate asc) as ctoipseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'In Progress' AND System_State = 'Build' then 1 else 2 end), System_ChangedDate asc) as iptobseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'Build' AND System_State = 'Resolved' then 1 else 2 end), System_ChangedDate asc) as btoresseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'Resolved' AND System_State = 'Done' then 1 else 2 end), System_ChangedDate asc) as restodseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'Resolved' AND System_State = 'Failed' then 1 else 2 end), System_ChangedDate asc) as restofseq 
    ,row_number() over (partition by System_Id 
           order by (case when PreviousState = 'Failed' AND System_State = 'In Progress' then 1 else 2 end), System_ChangedDate asc) as ftoipseq 
FROM [Tfs_Warehouse].[dbo].[vDimWorkItemOverlay] as dwi1 
    LEFT JOIN [Tfs_Warehouse].[dbo].[DimPerson] AS dp 
    ON dwi1.System_ChangedBy__PersonSK = dp.PersonSK 

    WHERE System_Id IN (36708 

     --SELECT DISTINCT System_Id 

     --FROM 
     -- [Tfs_Warehouse].[dbo].[vDimWorkItemOverlay] AS dwi2 

     --WHERE System_State IN ('Failed') 
     --AND IterationLevel0 = 'v7' 
     --AND YEAR(System_CreatedDate) = 2017 
     ) 

) 

    SELECT * 

    FROM myTable 
    Where toNew = 1 or toCommited = 1 or toIP = 1 or toBuild = 1 or toResolved = 1 or toDone = 1 or toFailed = 1 or FailedtoIP = 1 
    Order by ID, RevisionNo 

何変化する。これは、row_number() over(partition)関数を使用しています。

enter image description here

におけるサブクエリ:「以前の状態=新規system_stateは=コミット」の最初のインスタンスに遭遇すると、列ntocomseqは、ここで(ソートの旗のような)1は、私の結果である必要がありますコメントアウトされていますが、それだけでは、これまでに失敗したことのある作業項目のリストをさらにフィルタリングしています。

私が抱えている問題は、アイテムが再び失敗して修正されたときに、クエリがそれをキャッチしていないことです。もしPreviousState=InProgressSystem_State=Buildが2回目に1を与えられなければ、実際には2つの場合があります。これを修正する別の方法がありますか? TfsWarehouse dbテーブルを使用している他の人に同様の問題が発生しましたか?

私が得たいのは、上記の結果ですが、バグのインスタンスがIn ProgressからBuildに2回目になります。ワークアイテムID全体を分割しているので、自分のパーティションに問題がある可能性があります。そのため、状態変更の最初のインスタンスだけを探していますが、一度だけ探しています。私は毎回変更の最初のインスタンスが必要です。

ご不明な点がありましたら、お気軽にお問い合わせください。うまくいけば、あまりにも混乱していることはありません。ここで

は、サンプルデータの一例である - 私はちょうど私がCTE

WorkItem PreviousState System_ChangedDate System_Id System_Title System_State System_Rev System_Reason System_CreatedDate 

<!-- --> 

Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor NULL   2017-07-19 15:40:12.873 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor New 1  New defect reported      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor New   2017-07-20 07:32:26.800 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Committed 2  Commitment made by the team 2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Committed  2017-07-20 07:32:28.907 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 3  Work started    2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 2017-07-20 07:32:31.660 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build  4  Build pending     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build   2017-07-20 07:32:34.410 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved 5  Fixed      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build   2017-07-20 07:33:55.623 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved 6  Fixed      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build   2017-07-20 12:09:26.707 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved 7  Fixed      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-07-20 12:09:54.177 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Failed  8  Bug not fixed     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-07-20 12:10:17.037 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Failed  9 Bug not fixed     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-07-20 12:12:53.960 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Failed  10  Bug not fixed     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Failed   2017-07-21 07:26:40.930 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 11 Work started    2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Failed   2017-07-24 07:36:44.370 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 12  Work started    2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 2017-07-24 10:16:37.360 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build  13  Build pending     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor In Progress 2017-07-24 10:16:45.373 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build  14  Build pending     2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build   2017-07-24 10:16:57.720 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved 15  Fixed      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Build   2017-07-24 10:17:38.133 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved 16  Fixed      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-07-24 10:17:44.010 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 17 Resolution accepted  2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-07-25 15:25:36.490 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 18  Resolution accepted      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-08-11 13:54:08.960 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 19  Resolution accepted      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-10-10 15:09:32.593 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 20  Resolution accepted      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-10-10 15:33:41.343 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 21  Resolution accepted      2017-07-19 15:40:12.873 
Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Resolved  2017-10-10 15:35:01.910 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor Done 22  Resolution accepted      2017-07-19 15:40:12.873 
+0

小さなサンプルデータを与えることができれば、単一の作業項目でおそらく解決しやすくなります。元のデータがどのように見えるか分からないため、cteの結果はあまり役に立たない。説明は素晴らしかったが、サンプルデータと期待される出力は、MCVEにとって重要なものになるだろう。 – scsimon

+0

応答と良い点をありがとう。私は先に進み、サンプルデータのキャプチャを追加しました。これは私の元の例で描いたのと同じ作業項目です。 – dougie88

+0

Cool @ dougie88。それをテスト環境にコピーできるようにテキストとして貼り付けることができますか?画像はあまりフレンドリーではありません。 – scsimon

答えて

1

に使用していた列を選択して[OK]を、私はあなたをフォローていると思います。これがあなたになりたいと思ったら、私に教えてください。 2012年のため、LEADLAGを使用できます。下のスニペットでは、2つの余分な列を作成しています。前の行または次の行に基づいて行が変更されたときに、それらのフラグはフラグを立てます。つまり、本質的にはデータをある意味で「重複除外」します。これを最初に実行し、CurrentState列と私が追加した2つの列に注目してください。そして、あなたが望む行にそれらを制限するためにコメントアウトした適切なwhere節を使用することができます。

declare @table table(
         WorkItem varchar(4000) 
         ,PreviousState varchar(256) null 
         ,ChangedDate datetime2 
         ,ID int 
         ,Title varchar(4000) 
         ,CurrentState varchar(256) 
         ,RevisionNo int 
         ,Reason varchar(256) 
         ,CreatedDate datetime2) 
insert into @table 
values 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor',NULL,'2017-07-19 15:40:12.873',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','New',1,'New defect reported','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','New','2017-07-20 07:32:26.800',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Committed',2,'Commitment made by the team','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Committed','2017-07-20 07:32:28.907',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress',3,'Work started','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress','2017-07-20 07:32:31.660',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build',4,'Build pending','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build','2017-07-20 07:32:34.410',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved',5,'Fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build','2017-07-20 07:33:55.623',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved',6,'Fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build','2017-07-20 12:09:26.707',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved',7,'Fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-07-20 12:09:54.177',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Failed',8,'Bug not fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-07-20 12:10:17.037',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Failed',9,'Bug not fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-07-20 12:12:53.960',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Failed',10,'Bug not fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Failed','2017-07-21 07:26:40.930',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress',11,'Work started','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Failed','2017-07-24 07:36:44.370',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress',12,'Work started','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress','2017-07-24 10:16:37.360',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build',13,'Build pending','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','In Progress','2017-07-24 10:16:45.373',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build',14,'Build pending','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build','2017-07-24 10:16:57.720',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved',15,'Fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Build','2017-07-24 10:17:38.133',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved',16,'Fixed','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-07-24 10:17:44.010',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',17,'Resolution accepted','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-07-25 15:25:36.490',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',18,'Resolution accepted','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-08-11 13:54:08.960',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',19,'Resolution accepted','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-10-10 15:09:32.593',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',20,'Resolution accepted','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-10-10 15:33:41.343',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',21,'Resolution accepted','2017-07-19 15:40:12.873'), 
('Bug 36708 MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Resolved','2017-10-10 15:35:01.910',36708,'MEP Reno: Can edit stylegroup of child platform views and form dimensions of grandchild platform views in detailed editor','Done',22,'Resolution accepted','2017-07-19 15:40:12.873') 


;with cte as(
select 
    * 
    ,RevisionNumber = row_number() over (partition by ID order by ChangedDate) 
    ,FirstInstance = case when lag(CurrentState) over (partition by ID order by ChangedDate) = CurrentState then 0 else 1 end 
    ,LastInstance = case when lead(CurrentState) over (partition by ID order by ChangedDate) = CurrentState then 0 else 1 end 
from @table) 

select 
    * 
from cte 
order by ID, ChangedDate 
--where FirstInstance = 1 
--where LastInstance = 1 
+1

うわー、それは動作します!非常に良い仕事、私はあなたの助けに感謝します!私が今できることは、元のケースステートメントを変更し、それを個々の状態変更の追加のフラグとして設定することです。つまり、解決されなかった場合はchar Fまたはその性質のものになります。どうもありがとう! – dougie88

+0

@ dougie88に全く心配はありません – scsimon

関連する問題