CREATE PROC PROC_KFTC_Id_Expiry  
(  
	 @FLAG      	VARCHAR(50)  	= NULL  
	,@email    		VARCHAR(100) 	= NULL  
	,@walletAccountNo VARCHAR(100) 	= NULL 
	--grid parameters  
	,@pageSize     	VARCHAR(50)  	= NULL  
	,@pageNumber    VARCHAR(50)  	= NULL  
	,@sortBy     	VARCHAR(50)  	= NULL  
	,@sortOrder     VARCHAR(50)  	= NULL  
	,@user        	VARCHAR(50)  	= NULL	
)  
AS  
SET NOCOUNT ON;  
SET XACT_ABORT ON;  
BEGIN  
	DECLARE  @table    			VARCHAR(MAX)  
			,@select_field_list VARCHAR(MAX)  
			,@extra_field_list 	VARCHAR(MAX)  
			,@sql_filter  		VARCHAR(MAX)  
  
	IF @FLAG = 'S'  
	BEGIN  
		SET 	@sortBy = 'CUSTOMERID'  
		DECLARE @expireDate AS Datetime
		SET 	@expireDate =(SELECT  CAST( FORMAT(Getdate(),'yyyy-MM-dd') + ' 23:59:59' as DATETIME))
		SET 	@expireDate = DATEADD(MONTH,1 ,@expireDate)
		SET @table ='(  
					select   C.customerId,C.FirstName,c.nativeCountry, cm.countryName as NativeCountryName,c.email,C.mobile,kb.bankname,C.createddate as RegisterDate,kft.accessTokenExpTime as idExpiryDate, c.walletAccountNo
					from customerMaster(nolock) C
					inner join KFTC_CUSTOMER_MASTER(nolock) kft on kft.customerId=c.customerId
					inner join countrymaster(nolock) cm on cm.countryId=c.nativeCountry
					inner join KoreanBankList(nolock) kb on kb.rowid = c.bankname
					where C.idExpiryDate  <='''+   CONVERT(VARCHAR,@expireDate,110) + ''')X'  
		--print(@table)
		
		SET @sql_filter = ''  
  
		IF ISNULL(@email,'') <> ''  
			SET @sql_Filter = @sql_Filter + ' AND email = ''' +@email+''''  
  
		IF ISNULL(@walletAccountNo,'') <> ''  
			SET @sql_Filter = @sql_Filter + ' AND walletAccountNo = ''' +@walletAccountNo+'''' 
		
		SET @select_field_list ='customerId,FirstName,email,NativeCountryName,nativeCountry,mobile,bankname,RegisterDate,idExpiryDate'   
		
		EXEC dbo.proc_paging  
				@table,@sql_filter,@select_field_list,@extra_field_list  
				,@sortBy,@sortOrder,@pageSize,@pageNumber  
	END  
	
END  





