应该输入的select语句的存储过程

时间:2014-03-01 21:25:33

标签: sql sql-server stored-procedures

任何人都可以帮我解决以下

的商店程序

select语句应该输入completeddatekey

位于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

1 个答案:

答案 0 :(得分: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'