Sunday, 6 February 2022

sql pagelist filter

 >>sql get page list with filter values and pagenation.

if id is not passing make it null then get all values.

hre i am passing id as int so if i pass id 0 then make it null.

COALESCE(NULLIF(@AgentID, '')

here is code.

  

ALTER PROC  [Master].[usp_AccountPageView] 

      

  @AgentID int,  

    

 @Status bit,      

 @PageNo smallint,      

 @Rows smallint ,

@ProfileStatus bit

   

AS       

BEGIN     


   

 ;with AdminStatus as (select lookupid,lookupdescription from config.lookup where LookupCategory='ADMINSTATUS')      

 SELECT Ac.[ID], Ac.[AgentID], Ac.[AccountName], Ac.[ContactPerson], Ac.[EmailID], Ac.[Password], Ac.[MobileNo], Ac.[AdminStatus], Ac.[Status], Ac.[CreatedOn], Ac.[CreatedBy],      

 ISNULL(b.LookupDescription,'') As AdminStatusDescription,Ag.AgencyName ,Ac.ProfileStatus      

 FROM   [Master].[Account] Ac      

 left outer join AdminStatus b on       

  Ac.adminstatus = b.LookupID      

 Left Outer Join Master.Agent Ag ON      

  Ac.AgentID = Ag.ID      

 Where       

  Ac.AgentID = COALESCE(NULLIF(@AgentID, ''), Ac.AgentID)  

  And Ac.Status = @Status 

  And Ac.ProfileStatus=@ProfileStatus

 ORDER BY Ac.[ID]        

 OFFSET @Rows * @PageNo ROWS      

 Fetch NEXT @Rows ROWS ONLY      

      

END      

-- ========================================================================================================================================      

-- END              [Master].[usp_AccountPageView]      

-- ======================================================================================================================================== 


go




ALTER PROC [Master].[usp_AccountRecordCount] 

@AgentID int,

@Status bit,

@PageNo smallint,

@Rows smallint,

@ProfileStatus bit

AS 

BEGIN




if @AgentID = 0

select @AgentID=null



SELECT COUNT(0) 

FROM   [Master].[Account] Ac

Left Outer Join Master.Agent Ag ON

Ac.AgentID = Ag.ID

Where

Ac.AgentID = COALESCE(NULLIF(@AgentID, ''), Ac.AgentID)  

And Ac.Status = @Status 

And Ac.ProfileStatus =@ProfileStatus 


END


-- ========================================================================================================================================

-- END  [Master].[usp_AccountRecordCount]

-- ========================================================================================================================================


GO



No comments:

Post a Comment

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...