2017-05-19 16 views
-4

のためのケースを定義する私は、次の文でJobTimeを表示する:次のように時間条件

SELECT DISTINCT 
CASE WHEN [PRIORITY_TYPE_NAME] = 'Urgent' AND ISNULL(JobTime,0) <=240 THEN 'NOC Service Request Resolution - Urgent' 
    WHEN [PRIORITY_TYPE_NAME] = 'High' AND ISNULL(JobTime,0) <=720 THEN 'NOC Service Request Resolution - High' 
    WHEN [PRIORITY_TYPE_NAME] = 'Medium' AND ISNULL(JobTime,0) <=1440 THEN 'NOC Service Request Resolution - Medium' 
    WHEN [PRIORITY_TYPE_NAME] = 'Low' AND ISNULL(JobTime,0) <=2880 THEN 'NOC Service Request Resolution - Low' 
END AS [Problem_Type_Name] 

JobTimeの計算は次のとおりです。

CASE WHEN (case when [Escalated to Resolved time] is null then (ISNULL([Escalated to Resolved time],0) + ISNULL([Escalated to Closed time],0)- ISNULL([hold time],0)) else (ISNULL([Escalated to Closed time],0) - ISNULL([hold time],0)) end) <0THEN 0 ELSE (case when [Escalated to Resolved time] is null then (ISNULL([Escalated to Resolved time],0) + ISNULL([Escalated to Closed time],0)- ISNULL([hold time],0)) else (ISNULL([Escalated to Closed time],0) - ISNULL([hold time],0)) end) END AS JobTime 

はJobTimeを使用するには、すべての可能なまたは簡単な方法はあります選択で?

+3

編集あなたの質問をフィールドを参照し、サンプルデータと望ましい結果を提供できるようになる、適用外にあなたのケース文を置くことができます。あなたの質問に対する答えは、 'SELECT'で' JobTime'を使う方法がたくさんあります。 –

+0

質問を理解しやすくするために質問を編集せずに回答が受け入れられたので、私は閉じることにしました。 – halfer

答えて

0

あなたは、あなたのSELECT文で

SELECT DISTINCT 
CASE WHEN [PRIORITY_TYPE_NAME] = 'Urgent' AND ISNULL(JobTime,0) <=240 THEN 'NOC Service Request Resolution - Urgent' 
    WHEN [PRIORITY_TYPE_NAME] = 'High' AND ISNULL(JobTime,0) <=720 THEN 'NOC Service Request Resolution - High' 
    WHEN [PRIORITY_TYPE_NAME] = 'Medium' AND ISNULL(JobTime,0) <=1440 THEN 'NOC Service Request Resolution - Medium' 
    WHEN [PRIORITY_TYPE_NAME] = 'Low' AND ISNULL(JobTime,0) <=2880 THEN 'NOC Service Request Resolution - Low' 
END AS [Problem_Type_Name], 
oa.JobTime 

FROM dbo.TableName (NOLOCK) t 
OUTER APPLY ( 
        SELECT CASE WHEN (case when [Escalated to Resolved time] is null then (ISNULL([Escalated to Resolved time],0) + ISNULL([Escalated to Closed time],0)- ISNULL([hold time],0)) else (ISNULL([Escalated to Closed time],0) - ISNULL([hold time],0)) end) <0THEN 0 ELSE (case when [Escalated to Resolved time] is null then (ISNULL([Escalated to Resolved time],0) + ISNULL([Escalated to Closed time],0)- ISNULL([hold time],0)) else (ISNULL([Escalated to Closed time],0) - ISNULL([hold time],0)) end) END AS JobTime 
      ) oa 
関連する問題