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.

61 lines
4.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_certificateExpiryReport] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE procEDURE [dbo].[proc_certificateExpiryReport]
  9. @flag VARCHAR(50) = NULL
  10. ,@id INT = NULL
  11. ,@user VARCHAR(200) = NULL
  12. ,@agentId VARCHAR(10) = NULL
  13. ,@createdDate DATETIME = NULL
  14. ,@createdBy VARCHAR(30) = NULL
  15. ,@sortBy VARCHAR(50) = NULL
  16. ,@sortOrder VARCHAR(5) = NULL
  17. ,@pageSize INT = NULL
  18. ,@pageNumber INT = NULL
  19. ,@fromDate VARCHAR(20) = NULL
  20. ,@toDate VARCHAR(20) = NULL
  21. AS
  22. SET NOCOUNT ON
  23. BEGIN
  24. IF @flag = 'rpt'
  25. BEGIN
  26. DECLARE @sql VARCHAR(MAX)
  27. SET @sql ='SELECT
  28. [S.N.] = row_number()over(order by am.agentState,am.agentName)
  29. ,[Agent Id] = am.agentId
  30. ,[Zone] = am.agentState
  31. ,[District] = am.agentDistrict
  32. ,[Agent Name] = am.agentName
  33. ,[Phone] = am.agentPhone1
  34. ,[User Name] = au.userName
  35. ,[Exp.Date] = CONVERT(VARCHAR,DATEADD(year,1,au.dcApprovedDate),101)
  36. FROM applicationUsers au WITH(NOLOCK)
  37. INNER JOIN agentMaster am WITH(NOLOCK) ON am.agentId = au.agentId
  38. WHERE
  39. ISNULL(au.isDeleted,''n'')<>''Y''
  40. AND ISNULL(au.isActive,''Y'')=''Y''
  41. AND ISNULL(am.agentBlock,''U'') = ''U''
  42. AND DATEADD(year,1,au.dcApprovedDate) BETWEEN '''+@fromDate+''' AND '''+@toDate+' 23:59:59'''
  43. IF @agentId IS NOT NULL
  44. SET @sql = @sql + ' AND am.agentId='''+ @agentId +''''
  45. EXEC(@sql)
  46. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', NULL
  47. SELECT 'Date Range' head, 'From '+CONVERT(VARCHAR,@fromDate,101)+' to '+CONVERT(VARCHAR,@toDate,101) value UNION All
  48. SELECT 'Agent Name' head,case when @agentId is null then 'All Agent' else
  49. (SELECT agentName FROM agentMaster WITH(NOLOCK) WHERE agentId=@agentId) end VALUE
  50. SELECT 'Certificate Expiry Report' title
  51. END
  52. END
  53. GO