2016-08-05 15 views
0
SELECT HD.Login_ID 
    ,HD.Site_Group 
    ,HD.Incident_Number 
    ,HD.Internet_E_mail 
    ,HD.Assigned_Group 
    ,HD.Assignee 
    ,HD.Status_Reason 
    ,HD.Description 
    ,HD.Detailed_Decription 
    ,HD.Priority 
    ,HD.Submit_Date 
    ,HD.STATUS 
    ,HD.Entry_ID 
    ,HD.Service_Type 
    ,(SM.SVTDueDate - DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()))/60/60 AS SLM_HOURS 
    ,(SM.SVTDueDate - DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()))/60 AS SLM_MINUTES 
    ,SM.SVTDueDate 
    ,WL.Detailed_Description AS Work_Log_Description 
    ,WL.Work_Log_Submitter 
    ,DATEADD(hour, 14, DATEADD(day, 25567, WL.Work_Log_Submit_Date/(60.0 * 60.0 * 24.0) - 0.25)) AS WORKLOGDATE 
    ,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - WL.Work_Log_Submit_Date)/60/60 AS WORK_AGE_HOURS 
    ,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - WL.Work_Log_Submit_Date)/60 AS WORK_AGE_MINUTES 
    ,CASE HD.SLM_STATUS 
     WHEN 2 
      THEN 'Warning' 
     WHEN 3 
      THEN 'Breached' 
     ELSE 'Within' 
     END AS SLM_STATUS 
    ,rsw.work_shift_code 
    ,HD.InstanceId 
    ,HD.Assignee_Login_ID 
    ,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - AL.Audit_Date)/60 AS ASSIGNED_AGE_MINUTES 
FROM HPD_Help_Desk AS HD 
LEFT OUTER JOIN SLM_Measurement AS SM ON HD.Incident_Number = SM.ApplicationUserFriendlyID 
LEFT OUTER JOIN HPD_WorkLog AS WL ON HD.Incident_Number = WL.Incident_Number 
LEFT OUTER JOIN reference.dbo.SAP_worker AS rsw ON HD.Internet_E_mail = LOWER(rsw.micron_username) + '@micron.com' 
LEFT OUTER JOIN HPD_HelpDesk_AuditLogSystem AS AL ON HD.Entry_ID = AL.Original_Request_ID 
WHERE (HD.Assigned_Group LIKE '%MSC%') 
    AND (
     HD.STATUS IN (
      '1' 
      ,'2' 
      ,'3' 
      ) 
     ) 
    AND HD.Assignee IS NOT NULL 
    AND (
     WL.Work_Log_Submit_Date IS NULL 
     OR WL.Work_Log_ID = (
      SELECT TOP 1 (Work_Log_ID) AS Expr1 
      FROM HPD_WorkLog AS ML 
      WHERE (Incident_Number = HD.Incident_Number) 
      ORDER BY Submit_Date DESC 
      ) 
     ) 
    AND (
     HD.Assigned_Group NOT IN (
      'MIL_MSC' 
      ,'TJP_MSC' 
      ,'MIT_MSC' 
      ,'MSL_MSC' 
      ) 
     ) 
    AND (HD.Assigned_Group IN (@Site_Name)) 
    AND (
     HD.Status_Reason <> 12000 
     OR HD.Status_Reason IS NULL 
     ) 
    AND (HD.Assignee_Login_ID IN @Assignee_List) 
    AND (
     AL.Audit_date IS NULL 
     OR AL.Audit_date = (
      SELECT MAX(Audit_date) AS Expr1 
      FROM HPD_HelpDesk_AuditLogSystem AS ALS 
      WHERE Fields_Changed LIKE ('%Assignee%') 
       AND (HD.Entry_ID = Original_Request_ID) 
      ) 
     AND (
      SM.Create_Date IS NULL 
      OR SM.Create_Date = (
       SELECT TOP 1 Create_Date 
       FROM SLM_Measurement 
       WHERE (ApplicationUserFriendlyID = HD.Incident_Number) 
       ORDER BY Create_Date DESC 
       ) 
      ) 
     ) 
+0

ようこそ! – JimHawkins

答えて

2

私はこのコードで見るだけで明らかにエラーが期待されているコンテキストで指定nonbooleanタイプの発現は、このラインであります正確なエラーですが、そうかもしれません。それはあなたが意図するものではありません、

HD.Assignee_Login_ID IN (@Assignee_List) 

しかし:

まず、INの構文は括弧が必要です。残念ながら、パラメータとしてリストを挿入することはできません。

  • 使用、動的SQL:

    あなたは基本的に3つのオプションがあります。

  • 使用多重比較(HD.Assignee_Login_ID IN (@Assignee_List1, @Assignee_List2, @Assignee_List3)
  • 使用LIKE

後者は次のようになります。あなたの質問は何です:-)スタックオーバーフローする

',' + @Assignee_List + ',' LIKE '%,' + CAST(@Assignee_List as VARCHAR(255)) + ',%'