You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
6.3 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_agentSearchAutocomplete] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. /*
  9. EXEC proc_agentSearchAutocomplete @FLAG='A',@user='ADMIN',@searchField='BAJ'
  10. EXEC proc_agentSearchAutocomplete @FLAG='b',@searchField='global'
  11. EXEC proc_agentSearchAutocomplete @FLAG='c',@searchField='baj'
  12. */
  13. CREATE proc [dbo].[proc_agentSearchAutocomplete]
  14. @flag VARCHAR(50) = NULL
  15. ,@user VARCHAR(30) = NULL
  16. ,@searchField VARCHAR(200) = NULL
  17. AS
  18. SET NOCOUNT ON;
  19. SET XACT_ABORT ON;
  20. BEGIN TRY
  21. IF @flag = 'a'
  22. BEGIN
  23. SELECT A.agentName,A.agentId FROM
  24. (
  25. SELECT TOP 20 agentId,agentName+' '+b.districtName agentName
  26. FROM agentMaster a WITH(NOLOCK) LEFT JOIN api_districtList b WITH(NOLOCK)
  27. ON a.agentLocation=b.districtCode
  28. WHERE (actAsBranch = 'Y' OR agentType = 2904)
  29. AND ISNULL(a.isDeleted, 'N') = 'N'
  30. AND ISNULL(a.isActive, 'N') = 'Y'
  31. )A WHERE A.agentName LIKE '%'+@searchField+'%' ORDER BY A.agentName
  32. END
  33. IF @flag = 'b' -- Populate agent bank List only
  34. BEGIN
  35. SELECT TOP 20 agentName+'|'+CAST(agentId AS VARCHAR) agentName,a.agentId
  36. FROM agentMaster a WITH(NOLOCK)
  37. WHERE isnull(isSettlingAgent,'N')='Y' and isnull(actAsBranch,'N')='N'
  38. AND ISNULL(a.isDeleted, 'N') = 'N'
  39. AND ISNULL(a.isActive, 'N') = 'Y'
  40. AND A.agentName LIKE '%'+@searchField+'%' ORDER BY A.agentName
  41. END
  42. IF @flag = 'c' -- Populate agent (IME Private Agents)
  43. BEGIN
  44. SELECT TOP 20 agentName+'|'+CAST(agentId AS VARCHAR) agentName,a.agentId FROM
  45. (
  46. SELECT agentId,agentName+' '+b.districtName agentName
  47. FROM agentMaster a WITH(NOLOCK) LEFT JOIN api_districtList b WITH(NOLOCK)
  48. ON a.agentLocation=b.districtCode
  49. WHERE actAsBranch = 'Y'
  50. AND agentType = 2903
  51. AND ISNULL(a.isDeleted, 'N') = 'N'
  52. AND ISNULL(a.isActive, 'N') = 'Y'
  53. )A WHERE A.agentName LIKE '%'+@searchField+'%' ORDER BY A.agentName
  54. END
  55. IF @flag = 'cv2' -- Populate agent (IME Private Agents) INCLUDING ime co-operative
  56. BEGIN
  57. --SELECT TOP 20 * FROM
  58. --(
  59. --SELECT a.agentId,a.agentName
  60. --FROM agentMaster a WITH(NOLOCK)
  61. --WHERE actAsBranch = 'Y'
  62. -- AND (agentType = 2903 and actAsBranch = 'Y')
  63. -- AND ISNULL(a.isDeleted, 'N') = 'N'
  64. -- OR (agentType = 2904)
  65. -- --OR (agentId = 20653)
  66. --)X WHERE agentName LIKE '%'+@searchField+'%'
  67. --ORDER BY agentName
  68. SELECT TOP 20 * FROM
  69. (
  70. SELECT a.agentId,a.agentName
  71. FROM agentMaster a WITH(NOLOCK)
  72. WHERE
  73. agentGrp <> '4301'
  74. AND ISNULL(a.isDeleted, 'N') = 'N'
  75. AND (
  76. (agentType = 2903 AND actAsBranch = 'Y')
  77. OR agentType = 2904
  78. )
  79. )X WHERE agentName LIKE '%'+@searchField+'%'
  80. ORDER BY agentName
  81. END
  82. END TRY
  83. BEGIN CATCH
  84. IF @@TRANCOUNT > 0
  85. ROLLBACK TRANSACTION
  86. DECLARE @errorMessage VARCHAR(MAX)
  87. SET @errorMessage = ERROR_MESSAGE()
  88. EXEC proc_errorHandler 1, @errorMessage, @user
  89. END CATCH
  90. GO