Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. ALTER view [STD].[view_expedient]
  2. as
  3.  
  4. Select
  5. convert(varchar(20), expedient.ExpedientID) + '-' + convert(varchar(20), IsNull(expedient_derivation.ExpedientDerivationID, 0)) ExpedientCompID,
  6. expedient.ExpedientID,
  7. IsNull(expedient_derivation.ExpedientDerivationID, 0) ExpedientDerivationID,
  8. expedient.IsDeleted,
  9. expedient.ExpedientNumber,
  10. expedient.DocTypeID,
  11. expedient.CategoryID,
  12. expedient.Campus,
  13. IsNull(expedient.DocumentNumber, '') DocumentNumber,
  14. expedient.RegisterDate,
  15. expedient.DueDate,
  16. expedient.ArrivalWay,
  17. expedient.[Priority],
  18. IsNull(priorities.[Description], '') PriorityName,
  19. ltrim(rtrim( IsNull(IsNull(external_company.RazSoc, expedient.ClientName), ''))) ExternalCompanyName,
  20. --'' ExternalCompanyName,
  21. IsNull(business_area.[Description], '') BusinessAreaName,
  22. (Case When IsNull(expedient.DueDate, 0) != 0 Then DATEDIFF(day, expedient.DueDate, getdate()) Else 0 End) NumberPastDue,
  23. --(Case When isnull(origin_management_derivation.descripcion_puesto, '') = '' then isnull(derivation_module.moduleDescription, '')
  24. -- Else IsNull(origin_management_derivation.descripcion_puesto collate SQL_Latin1_General_CP1_CI_AS, module.moduleDescription) End) ManagementOriginName,
  25. (case when parametro.Description is null then '' else UPPER(REPLACE(parametro.Description,'-' ,' ' )) end) ManagementOriginName,
  26. IsNull(expedient_derivation.OriginID, expedient.RolID) ManagementOriginId,
  27. (Case When IsNull(expedient_derivation.ExpedientDerivationID, 0) != 0 Then
  28. (Case When expedient_derivation.[type] = (Select ParameterID From tblSystemParameter Where IsDerivedTo = 1) Then 0 Else 1 End) Else 0 End) IsCopy,
  29. IsNull(expedient_derivation.DestinationID, '') DestinationID,
  30. IsNull(expedient.DelegationManagementId, '') DelegationManagementId,
  31. (Case When isnull(destination_management_derivation.descripcion_puesto, '') = '' then isnull(destination_module.moduleDescription, '')
  32. Else IsNull(destination_management_derivation.descripcion_puesto collate SQL_Latin1_General_CP1_CI_AS, module.moduleDescription) End) ManagementDestinationName,
  33.  
  34. IsNull(delegation_management.descripcion_puesto, '') ManagementDelegationName,
  35.  
  36. IsNull(expedient_derivation.StateID, expedient.StateId) StateID,
  37. IsNull(expedient_derivation.StateID, 0) StateDerivationID,
  38. IsNull(state_derivation.[Description], states.[Description]) StateName,
  39. expedient.Confidentiality,
  40. IsNull(expedient.[Subject], '') [Subject],
  41. document_type.[Description] DocumentTypeName,
  42. category.[Description] CategoryName,
  43. '' DerivationComment,
  44. '' CancelComment,
  45. LTrim(Lower(expedient.InsertUserId)) InsertUserId,
  46. (Case When IsNull(expedient.DelegationUserId, '') != '' Then expedient.DelegationUserId
  47. When expedient_derivation.StateID <> (Select ParameterID From STD.tblSystemParameter Where IsRegisterState = 1) Then IsNull(expedient_derivation.DestinationUserID, expedient.InsertUserId)
  48. Else expedient.InsertUserId End) DestinationUser,
  49. IsNull(expedient.DelegationUserId, '') DelegationUser,
  50. (Case When IsNull(expedient_courier.ReceivedDate, '') != '' Then 1 Else 0 End) IsCourierReceived,
  51. expedient_courier.ReceivedDate CourierReceivedDate,
  52. expedient_courier.SendDate CourierSendDate,
  53. IsNull(expedient_courier.Destination, '') Destination,
  54. (Case When IsNull((select count(*) from STD.tblExpedientDocument where ExpedientID = expedient.ExpedientID And IsDeleted = 0), 0) != 0 Then 1 Else 0 End) HasDocuments,
  55. (Case When IsNull((select count(*) from STD.tblExpedientDerivation where ExpedientID = expedient.ExpedientID And IsDeleted = 0), 0) != 0 Then 1 Else 0 End) HasDerivations,
  56. Isnull(expedient_derivation.Received,0) Received,
  57. Isnull(expedient_derivation.Worked,0) Worked,
  58. IsNull((Select Distinct 1 From STD.tblExpedientDerivation where ExpedientID = expedient.ExpedientID And Received = 1), 0) as Block,
  59. IsNull(courier.Name, '') CourierName,
  60. Sender,
  61. isnull(RolID, 0) as RolID,
  62. isnull(BusinessAreaID, 0) as BusinessAreaID,
  63. isnull(expedient_derivation.UpdateUserId, '') as DerivationUpdateUserId,
  64. isnull(SharepointID,0) as SharepointID
  65. From STD.tblExpedient expedient
  66. inner join STD.tblSystemParameter document_type on expedient.DocTypeID = document_type.ParameterID
  67. inner join STD.tblSystemParameter category on expedient.CategoryID = category.ParameterID
  68. inner join STD.tblSystemParameter states on expedient.StateID = states.ParameterID
  69. left join BDINTBANNER.ACCESS.TblGroupModule group_module on group_module.groupID = expedient.RolID aND group_module.campus = expedient.Campus
  70. left join BDINTBANNER.ACCESS.TblModule module on group_module.moduleID = module.moduleID
  71. left join STD.tblSystemParameter priorities on expedient.Priority = priorities.ParameterID
  72. left join STD.tblSystemParameter business_area on expedient.BusinessAreaID = business_area.ParameterID
  73. left join BDUCCI.dbo.tblInstitucion external_company on expedient.ExternalCompanyID = external_company.IDInstitucionN
  74. left join STD.tblExpedientCourier expedient_courier on expedient.ExpedientID = expedient_courier.ExpedientID
  75. left join STD.tblCourier courier on expedient_courier.CourierID = courier.CourierID
  76. left join STD.tblExpedientDerivation expedient_derivation on expedient.ExpedientID = expedient_derivation.ExpedientID And expedient_derivation.Type = 37
  77. left join STD.tblSystemParameter state_derivation on expedient_derivation.StateID = state_derivation.ParameterID
  78.  
  79. left join BDINTBANNER.ACCESS.TblGroupModule derivation_group_module on derivation_group_module.groupID = expedient_derivation.OriginID And derivation_group_module.campus = expedient.Campus
  80. left join BDINTBANNER.ACCESS.TblModule derivation_module on derivation_group_module.moduleID = derivation_module.moduleID
  81.  
  82. left join BDINTBANNER.ACCESS.TblGroupModule destination_group_module on destination_group_module.groupID = expedient_derivation.DestinationID And destination_group_module.campus = expedient.Campus
  83. left join BDINTBANNER.ACCESS.TblModule destination_module on destination_group_module.moduleID = destination_module.moduleID
  84.  
  85. --left join [BDINTBANNER].[ADRYAN].[Tbl_puesto_compania] origin_management_derivation on expedient_derivation.OriginID = origin_management_derivation.puesto collate SQL_Latin1_General_CP1_CI_AS and origin_management_derivation.compania = '01' collate SQL_Latin1_General_CP1_CI_AS
  86. left join [DEGREES].[std].[tblSystemParameter] parametro on expedient.RolID=parametro.Code
  87. left join [BDINTBANNER].[ADRYAN].[Tbl_puesto_compania] destination_management_derivation on expedient_derivation.DestinationID = destination_management_derivation.puesto collate SQL_Latin1_General_CP1_CI_AS and destination_management_derivation.compania ='01' collate SQL_Latin1_General_CP1_CI_AS
  88. left join [BDINTBANNER].[ADRYAN].[Tbl_puesto_compania] delegation_management on expedient.DelegationManagementId = delegation_management.puesto collate SQL_Latin1_General_CP1_CI_AS and destination_management_derivation.compania ='01' collate SQL_Latin1_General_CP1_CI_AS
  89.  
  90.  
  91. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement