Guest User

Untitled

a guest
Jan 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. -- USE Vue
  2.  
  3. IF DB_NAME() NOT IN ('VueDev', 'VueTest', 'VueRpt', 'VueMaint', 'Vue')
  4. BEGIN
  5.  
  6. USE tempdb
  7. RAISERROR('You are in the wrong database. This script must be run in the Vue database.', 16, 1);
  8. RETURN
  9.  
  10. END
  11. GO
  12.  
  13. IF OBJECT_ID('dbo.vspGetBiometricsForGlobalAdd', 'P') IS NOT NULL
  14. BEGIN
  15.  
  16. DROP PROCEDURE dbo.vspGetBiometricsForGlobalAdd
  17.  
  18. END
  19. GO
  20.  
  21. SET ANSI_NULLS ON
  22. GO
  23. SET QUOTED_IDENTIFIER ON
  24. GO
  25.  
  26.  
  27.  
  28. CREATE PROCEDURE [dbo].[vspGetBiometricsForGlobalAdd]
  29. @BiometricTypeCode VARCHAR(4),
  30. @RegistrationIDsString VARCHAR(MAX)
  31. AS
  32. /*************************************************************************************************
  33. *
  34. * Name:
  35. *
  36. * vspGetBiometricsForGlobalAdd
  37. *
  38. * Input Parameters:
  39. * @BiometricTypeCode - The type of biometric to search for.
  40. * (See ExamDeliveryBiometric.BiometricTypeCode)
  41. * @RegistrationIDsString - Comma-delimited list of registration IDs (i.e. OrderItemIDs)
  42. *
  43. * Description:
  44. *
  45. * For a given list of registration IDs, retrieves the ExamDeliveryBiometric records to be
  46. * used to add biometrics for those registrations to the Global Datastore (for 1:N comparison).
  47. *
  48. * Returns only those biometrics with BiometricTypeCode set to @BiometricTypeCode.
  49. * Returns only those biometrics with BiometricCaptureContextCode set to 'ADMT'.
  50. * Returns only those biometrics that exist in the file system. (have not been deleted.)
  51. *
  52. * May return zero or one record for each registration ID. If there is more than one record
  53. * that matches the criteria, this will return only one: the one with the most recent
  54. * ExamDeliveryBiometric.CaptureDate.
  55. *
  56. * Returns:
  57. *
  58. * ExamDeliveryBiometric.*
  59. *
  60. * Revision History:
  61. *
  62. * 12/09/2010 - Marnee DeRider
  63. * Initial release.
  64. *
  65. * 2/28/2011 - Steve Hummel
  66. * Updated to include ExamDeliveryBiometric.IsBiometricFileDeleted = 0 to exclude deleted biometrics
  67. *
  68. * 09/08/2011 - mckibta
  69. * Rewritten for performance improvement
  70. *
  71. *
  72. * Copyright © 2010 Pearson VUE, Inc. All rights reserved.
  73. *
  74. *************************************************************************************************/
  75.  
  76. BEGIN
  77. SET NOCOUNT ON
  78. SET XACT_ABORT ON
  79.  
  80. DECLARE @Command VARCHAR(MAX)
  81.  
  82. SET @Command = '
  83. SELECT
  84. LatestCapturedBiometric.ExamDeliveryBiometricID,
  85. LatestCapturedBiometric.OrderItemID,
  86. LatestCapturedBiometric.BiometricTypeCode,
  87. LatestCapturedBiometric.BiometricCaptureContextCode,
  88. LatestCapturedBiometric.CaptureDate,
  89. LatestCapturedBiometric.BiometricPath,
  90. LatestCapturedBiometric.Operator_ID,
  91. LatestCapturedBiometric.AppName,
  92. LatestCapturedBiometric.LastUpdate,
  93. LatestCapturedBiometric.LastUpdateAppUserID,
  94. LatestCapturedBiometric.IsBiometricFileDeleted
  95. FROM
  96. (
  97. SELECT
  98. ExamDeliveryBiometric.ExamDeliveryBiometricID,
  99. ExamDeliveryBiometric.OrderItemID,
  100. ExamDeliveryBiometric.BiometricTypeCode,
  101. ExamDeliveryBiometric.BiometricCaptureContextCode,
  102. ExamDeliveryBiometric.CaptureDate,
  103. ExamDeliveryBiometric.BiometricPath,
  104. ExamDeliveryBiometric.Operator_ID,
  105. ExamDeliveryBiometric.AppName,
  106. ExamDeliveryBiometric.LastUpdate,
  107. ExamDeliveryBiometric.LastUpdateAppUserID,
  108. ExamDeliveryBiometric.IsBiometricFileDeleted,
  109. Ranking = ROW_NUMBER() OVER(PARTITION BY ExamDeliveryBiometric.OrderItemID ORDER BY ExamDeliveryBiometric.CaptureDate DESC)
  110. FROM dbo.ExamDeliveryBiometric
  111. WHERE ExamDeliveryBiometric.BiometricTypeCode = ''' + @BiometricTypeCode + '''
  112. AND ExamDeliveryBiometric.BiometricCaptureContextCode = ''ADMT''
  113. AND ExamDeliveryBiometric.IsBiometricFileDeleted = 0
  114. AND ExamDeliveryBiometric.OrderItemID IN (SELECT ' + REPLACE(@RegistrationIDsString, ',', ' UNION ALL SELECT ') + ')
  115. ) AS LatestCapturedBiometric
  116. WHERE LatestCapturedBiometric.Ranking = 1
  117. '
  118.  
  119. EXECUTE (@Command)
  120.  
  121. END
  122.  
  123. GO
  124. GRANT EXECUTE ON [dbo].[vspGetBiometricsForGlobalAdd] TO [ReadPublicData] AS [dbo]
  125. GO
  126. GRANT EXECUTE ON [dbo].[vspGetBiometricsForGlobalAdd] TO [VTSAppUsers] AS [dbo]
  127. GO
Add Comment
Please, Sign In to add comment