2014-03-01 48 views
1

任何人都可以請幫我店裏程序應採取的completeddatekey其輸入端存儲過程SELECT語句應採取輸入

是在選擇底部以下

select語句聲明

completedDateKey充滿在此代碼的關鍵,但我需要的是應該採取completeddatekey的輸入端的存儲過程

SELECT FactId 
     ,UserType 
     ,wr.WorkRequestId 
     ,wr.XerisUserKey 
     ,xu.CsuserUserID UserId 
     ,u.fname UserFName 
     ,u.lname UserLName 
     ,b.PatientId 
     ,p.firstname PatFName 
     ,p.lastname PatLName 
     ,GroupId 
     ,HospiceGroupKey GroupKey 
     ,WR.ContactKey 
     ,C.ContactId 
     ,C.FirstName 
     ,C.LastName 
     ,Convert(datetime, 
       (Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)) Start_dtm 
     ,Convert(datetime, 
       (Convert(varchar, CD.Date,101) + ' ' + CT.TimeOfDay)) End_dtm 
     ,DATEDIFF(s, 
       Convert(datetime, 
         (Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)), 
       Convert(datetime, 
         (Convert(varchar, CD.Date,101) + ' ' + CT.TimeOfDay))) WRDuration 
     ,(Convert(Decimal(18,3), DATEDIFF(s,Convert(datetime,(Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)), Convert(datetime,(Convert(varchar, CD.Date,101) + ' '   + CT.TimeOfDay))))) * (Convert(Decimal(18,3),LineItemCount)/Convert(Decimal(18,3),PatientBucketItemCount)) Duration 
     ,CallBackNumber 
     ,WorkRequestType 
     ,B.LineItemCount 
     ,ArchiveLocation 
     ,Processed 
     ,ArchiveQueueType 
     ,TQA 
     ,Exclude 
     ,CallId 
FROM bi.dbo.FactWorkRequestTouches (NOlock) WR 
INNER JOIN bi.dbo.BridgePatientWorkRequest B ON B.WorkRequestId = WR.WorkRequestId 
INNER JOIN bi.dbo.dimPatient (NOlock) P ON B.PatientId = P.CphPatientID 
INNER JOIN bi.dbo.DimXerisUsers (NOlock) XU ON WR.XerisUserKey = XU.XerisUserKey 
INNER JOIN cdc.dbo.csuser (NOlock) U ON XU.CsuserUserID = u.user_id 
INNER JOIN bi.dbo.DimTimeOfDay (NOlock) ST ON WR.StartTimeOfDayKey = ST.TimeKey 
INNER JOIN bi.dbo.DimTimeOfDay (NOlock) CT ON WR.CompletedTimeOfDayKey = CT.TimeKey 
INNER JOIN bi.dbo.DimDate (NOlock) SD ON WR.StartDateKey = SD.DateKey 
INNER JOIN bi.dbo.DimDate (NOlock) CD ON WR.CompletedDateKey = CD.DateKey 
LEFT OUTER JOIN bi.dbo.DimContact (Nolock) C ON WR.ContactKey = C.ContactKey 
left outer join ssdba.excelleRx_WebFOCUS.dbo.DimHospiceHiearchy as h with (nolock) on     b.groupid = h.group_id 

WHERE CompletedDateKey = '20140131' 
    AND ArchiveQueueType = 0 
    AND PatientBucketItemCount <> 0 
    AND Exclude = 0 
    AND P.ENDDate is Null 
+0

請acccept我的答案,如果它已經爲你工作的過程。如果你接受答案,那麼它也會增加你的聲望。如果你不接受答案,那麼沒有人會投入時間尋找答案。 – DevelopmentIsMyPassion

+0

好的。感謝您的信息。 – user3369060

回答

1

它非常簡單。只要創建像下面

create procedure MyProc(
@CompletedDateKey varchar(20)) 

as 
Begin 
    SELECT FactId 
    ,UserType 
    ,wr.WorkRequestId 
    ,wr.XerisUserKey 
    ,xu.CsuserUserID UserId 
    ,u.fname UserFName 
    ,u.lname UserLName 
    ,b.PatientId 
    ,p.firstname PatFName 
    ,p.lastname PatLName 
    ,GroupId 
    ,HospiceGroupKey GroupKey 
    ,WR.ContactKey 
    ,C.ContactId 
    ,C.FirstName 
    ,C.LastName 
    ,Convert(datetime, 
      (Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)) Start_dtm 
    ,Convert(datetime, 
      (Convert(varchar, CD.Date,101) + ' ' + CT.TimeOfDay)) End_dtm 
    ,DATEDIFF(s, 
      Convert(datetime, 
        (Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)), 
      Convert(datetime, 
        (Convert(varchar, CD.Date,101) + ' ' + CT.TimeOfDay))) WRDuration 
    ,(Convert(Decimal(18,3), DATEDIFF(s,Convert(datetime,(Convert(varchar, SD.Date,101) + ' ' + ST.TimeOfDay)), Convert(datetime,(Convert(varchar, CD.Date,101) + ' '   + CT.TimeOfDay))))) * (Convert(Decimal(18,3),LineItemCount)/Convert(Decimal(18,3),PatientBucketItemCount)) Duration 
    ,CallBackNumber 
    ,WorkRequestType 
    ,B.LineItemCount 
    ,ArchiveLocation 
    ,Processed 
    ,ArchiveQueueType 
    ,TQA 
    ,Exclude 
    ,CallId 
    FROM bi.dbo.FactWorkRequestTouches (NOlock) WR 
INNER JOIN bi.dbo.BridgePatientWorkRequest B ON B.WorkRequestId = WR.WorkRequestId 
INNER JOIN bi.dbo.dimPatient (NOlock) P ON B.PatientId = P.CphPatientID 
INNER JOIN bi.dbo.DimXerisUsers (NOlock) XU ON WR.XerisUserKey = XU.XerisUserKey 
INNER JOIN cdc.dbo.csuser (NOlock) U ON XU.CsuserUserID = u.user_id 
INNER JOIN bi.dbo.DimTimeOfDay (NOlock) ST ON WR.StartTimeOfDayKey = ST.TimeKey 
INNER JOIN bi.dbo.DimTimeOfDay (NOlock) CT ON WR.CompletedTimeOfDayKey = CT.TimeKey 
INNER JOIN bi.dbo.DimDate (NOlock) SD ON WR.StartDateKey = SD.DateKey 
INNER JOIN bi.dbo.DimDate (NOlock) CD ON WR.CompletedDateKey = CD.DateKey 
LEFT OUTER JOIN bi.dbo.DimContact (Nolock) C ON WR.ContactKey = C.ContactKey 
left outer join ssdba.excelleRx_WebFOCUS.dbo.DimHospiceHiearchy as h with (nolock) on     b.groupid = h.group_id 

WHERE CompletedDateKey = @CompletedDateKey 
AND ArchiveQueueType = 0 
AND PatientBucketItemCount <> 0 
AND Exclude = 0 
AND P.ENDDate is Null 
End 

執行它像

Execute MyProc '20140131' 
+0

這位傢伙問了同樣的問題3次.. – Mihai

相關問題