raghavcinch

Untitled

Aug 19th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. USE [m5db]
  2. GO
  3.  
  4. /****** Object: View [dbo].[VwProfileDetails] Script Date: 11-08-2016 10:32:24 ******/
  5. DROP VIEW [dbo].[VwProfileDetails]
  6. GO
  7.  
  8. /****** Object: View [dbo].[VwProfileDetails] Script Date: 11-08-2016 10:32:24 ******/
  9. SET ANSI_NULLS ON
  10. GO
  11.  
  12. SET QUOTED_IDENTIFIER ON
  13. GO
  14.  
  15.  
  16. CREATE VIEW [dbo].[VwProfileDetails]
  17. AS
  18. select
  19. pr.Id,
  20. pr.ProfileTypeId,
  21. pr.Extension,
  22. prt.Name as ProfileTypeName,
  23. pr.ProfileStatusId,
  24. prn.Name as ProfileStatusName,
  25. pr.IsInDirectory,
  26. pr.IsPrimary,
  27. l.AccountId,
  28. coalesce(pe.FirstName, pr.BoblFirstName) as FirstName,
  29. coalesce(pe.LastName, pr.BoblLastName) as LastName,
  30. coalesce(ltrim(rtrim(pe.FirstName + ' ' + pe.LastName)), pr.InternalCallerId) as FullName,
  31. pr.InternalCallerId,
  32. coalesce(pe.BusinessEmail, pr.BoblEmail) as BusinessEmail,
  33. a.Id as AddressId,
  34. a.Address,
  35. a.Address2,
  36. a.City,
  37. a.StateId,
  38. a.CountryId,
  39. a.ZipCode,
  40. s.Name as State,
  41. co.Name as Country,
  42. l.Id as LocationId,
  43. pe.Id as PersonId,
  44. pr.TnId as [Tn],
  45. pr.TnCountryId as TnCountryId,
  46. coalesce(l.Name, a.Address + ' ' + a.Address2 + ', ' + a.City + ', '+s.Name ) as LocationName,
  47. pr.SubscriberId,
  48. pt.ClusterId,
  49. cl.Name as [Cluster],
  50. cl.PlatformTypeId,
  51. plt.Name as [Platform],
  52. cast(case
  53. when lo.LockEnabled = 0 then 0
  54. when ul.FailedLoginCount IS null then 0 -- special case, fail on first login
  55. when ul.FailedLoginCount >= lo.MaxFailedLogins AND ul.DateLocked < DATEADD(HOUR,-cast(lo.LockDuration as int),GETUTCDATE()) then 0
  56. when ul.FailedLoginCount >= lo.MaxFailedLogins then 1
  57. else 0
  58. end AS bit) as ProfileLocked,
  59. cast(case
  60. when lo.LockEnabled = 0 then 0
  61. when ulp.FailedLoginCount IS null then 0 -- special case, fail on first login
  62. when ulp.FailedLoginCount >= lo.MaxFailedLogins AND ulp.DateLocked < DATEADD(HOUR,-cast(lo.LockDuration as int),GETUTCDATE()) then 0
  63. when ulp.FailedLoginCount >= lo.MaxFailedLogins then 1
  64. else 0
  65. end as bit) as PersonLocked,
  66. case
  67. when ulp.LastSuccess is null AND ul.LastSuccess is NULL then null
  68. when ulp.LastSuccess IS null then ul.LastSuccess
  69. when ul.LastSuccess IS null then ulp.LastSuccess
  70. when ul.LastSuccess < ulp.LastSuccess then ulp.LastSuccess
  71. else ul.LastSuccess
  72. end as [LastLogin],
  73. pr.IsSuspended,
  74. prod.Name as BundleName,
  75. pr.PartitionId
  76. from
  77. [Profile] pr left join [Person] pe with (nolock)
  78. on pr.PersonId = pe.Id
  79. inner join Partition pt with (nolock)
  80. on pr.PartitionId = pt.Id
  81. inner join ProfileStatus prn with (nolock)
  82. on pr.ProfileStatusId = prn.Id
  83. inner join ProfileType prt with (nolock)
  84. on pr.ProfileTypeId = prt.Id
  85. inner join Location l with (nolock)
  86. on pr.LocationId = l.Id
  87. inner join Account ac with (nolock)
  88. on l.AccountId = ac.Id
  89. inner join Cluster cl with (nolock)
  90. on pt.ClusterId = cl.Id
  91. inner join PlatformType plt with (nolock)
  92. on cl.PlatformTypeId = plt.Id
  93. inner join VwAccountLockout lo with (nolock)
  94. on pt.AccountId = lo.AccountId
  95. left join [Address] a with (nolock)
  96. on l.AddressId = a.Id
  97. left join StateProvince s with (nolock)
  98. on a.StateId = s.id
  99. left join Country co with (nolock)
  100. on a.CountryId = co.id
  101. left join access_UserLogin ul with (nolock)
  102. on ul.AccountId = lo.AccountId
  103. and ul.Username = pr.TnId
  104. left join access_UserLogin ulp with (nolock)
  105. on ulp.AccountId = lo.AccountId
  106. and ulp.Username = pe.Username
  107. left join service_serviceProvisioningBase spb on pr.id = spb.ProfileId
  108. --Operate only on Service as part of Bundle
  109. left join service_service svcA on svcA.ServiceProvisioningBaseId = spb.id and svcA.BundleServiceId is not null --and svcA.ServiceClassId in (select ServiceClassId from [service_ServiceClassProfileTypeMapping])
  110. left join service_service bundleSvc on svcA.BundleServiceId = bundleSvc.id
  111. left join billing_product prod on bundleSvc.productId = prod.id
  112. -- Fetch only profiles which are on a cluster associated with the account
  113. inner join AccountCluster acc
  114. on pt.ClusterId = acc.ClusterId and acc.AccountId = ac.Id
  115. where a.IsDeleted = 0 and (svcA.ServiceClassId in (select ServiceClassId from [service_ServiceClassProfileTypeMapping]) or svcA.ServiceClassId is null)and
  116. pr.ProfileStatusId = 0 -- only Active
  117. and 0 = pr.IsVoiceMailDeposit and 0 = pr.IsVoiceMailRetrieve -- Don't show these
  118. -- Fetch only profiles which are on a cluster associated with the account
  119. --and pt.clusterid in ( select Clusterid from AccountCluster where AccountId = l.AccountId )
  120.  
  121. GO
Add Comment
Please, Sign In to add comment