	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 

    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
      if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    
    --    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     6   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
         if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 

    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
      if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid <= 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    
    --    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   7    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
         if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 

    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
      if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid <= 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    
    --    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   8    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
    
          if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'asc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) ASC LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 

    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
      if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'id' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.id desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userid' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by a.userid desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
    --   ---------------------------------------------
    
      if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;  
    if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid <= 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if; 
    
   
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname = '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail = '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;    
	if myorder = 'desc' && mysortby = 'userfullname' && reportto > 0 && roleid > 0 && departmentid > 0 && userid > 0 && searchuserfullname != '' && searchemail != '' then 
	   set  @querypart7 = "  order by concat(a.firstname, ' ', a.lastname) desc LIMIT ? OFFSET ? ";
       SET @sqlv = concat(@querypart_result1, @querypart2, @querypart3, @querypart4, @querypart5 ,@querypart6, @querypart7);
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @canreadinadminpage, @canreadinadminpage2, @cancreateinadminpage, @cancreateinadminpage2, @caneditinadminpage, @caneditinadminpage2, @canactivateinadminpage, @canactivateinadminpage2, @candeactivateinadminpage, @candeactivateinadminpage2, @userid, @searchuserfullname, @searchemail, @reportto, @roleid, @departmentid, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
END  $$
DELIMITER ;
--  -------------------------------------------
