   SET grouptotalquantity = @grouptotalquantity;
   
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by p.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.name ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by p.name ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'groupcategoryname' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by c.name ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'groupcategoryname' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by c.name ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.createtimeutc ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id  WHERE p.name like ? AND p.status IN (?,?) order by p.createtimeutc ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by p.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.name DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by p.name DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'groupcategoryname' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by c.name DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'groupcategoryname' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by c.name DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && groupcategoryname = '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.status IN (?,?) order by p.createtimeutc DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && groupcategoryname = '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND p.status IN (?,?) order by p.createtimeutc DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.name ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.name ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'groupcategoryname' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by c.name ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'groupcategoryname' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by c.name ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.createtimeutc ASC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.createtimeutc ASC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.name DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.name DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'groupcategoryname' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by c.name DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'groupcategoryname' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by c.name DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && groupcategoryname != '' then SET @sqlv = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE c.name LIKE ? AND p.status IN (?,?) order by p.createtimeutc DESC,p.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && groupcategoryname != '' then SET @statement = "SELECT p.*, c.name 'groupcategoryname', c.id 'groupcategoryid' from wp_dragonecommercereservezyx987_group  p JOIN wp_dragonecommercereservezyx987_groupcategory c ON p.groupcategoryid = c.id WHERE p.name like ? AND c.name LIKE ? AND p.status IN (?,?) order by p.createtimeutc DESC,p.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @groupcategoryname, @groupstatus, @groupstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
END  $$

--  --------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercereservezyx987_getHandlingList`(
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN searchshownname varchar(200),
   IN searchdescription varchar(200),
   IN fromdate date,
   IN todate date,  
   IN handlingstatus int,
   OUT handlingtotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchshownname = CONCAT('%', searchshownname, '%');
   set @searchdescription = CONCAT('%', searchdescription, '%');
   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
 
   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 
   
   set @handlingstatus = 0;
   set @handlingstatus2 = 1;
   if handlingstatus = -1 then set @handlingstatus = 0; set @handlingstatus2 = 1; end if;
   if handlingstatus = 0 then set @handlingstatus = 0; set @handlingstatus2 = 0; end if;
   if handlingstatus = 1 then set @handlingstatus = 1; set @handlingstatus2 = 1; end if;
   
    if searchwords = '' && searchdescription = '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
    if searchwords = '' && searchdescription != '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
--  ##########################################################################3

      if searchwords = '' && searchdescription = '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
    if searchwords = '' && searchdescription != '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @handlingtotalquantity from ", " wp_dragonecommercereservezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;
    
   SET handlingtotalquantity = @handlingtotalquantity;
   
--  ==========================================================================================================================
--  ==========================================================================================================================
 
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    

    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
     
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
   --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
       --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
        if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    
    
        if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
        if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercereservezyx987_propertyvalue d LEFT JOIN wp_dragonecommercereservezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercereservezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercereservezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercereservezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercereservezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercereservezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercereservezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_HANDLING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @handlingstatus, @handlingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
END  $$

--  ---------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercereservezyx987_getLogList`(
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),   
   IN searchtype varchar(200),
   IN processname varchar(200),
   IN userid int,      
   IN logstatus int,
   OUT logtotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchtype = searchtype;
   set @processname = processname;
   set @userid = userid;   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   
   set @logstatus = 0;
   set @logstatus2 = 1;
   if logstatus = -1 then set @logstatus = 0; set @logstatus2 = 1; end if;
   if logstatus = 0 then set @logstatus = 0; set @logstatus2 = 0; end if;
   if logstatus = 1 then set @logstatus = 1; set @logstatus2 = 1; end if;
   
    if searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
	if searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if; 
    
    
    --   ####################################################################
 
     if searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
	if searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if; 
    
    -- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	-- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&   
	-- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	-- &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
         
	if searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
	if searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if; 
    
    
    --   ####################################################################
 
	if searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
	if searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = concat( 'Select count(*) into @logtotalquantity from ', ' wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2;
       DEALLOCATE PREPARE stmt;
    end if;
         
   SET logtotalquantity = @logtotalquantity;
   
--  ==========================================================================================================================
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname = '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname = '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2
    
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname != '' && userid <= 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname != '' && userid <= 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    --    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    --    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    --    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
        
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname = '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname = '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2    
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype = '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype = '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'type' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'type' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by `type` DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchtype != '' && processname != '' && userid > 0 then SET @sqlv = "SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @processname, @searchtype, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchtype != '' && processname != '' && userid > 0 then SET @statement = 'SELECT * from wp_dragonecommercereservezyx987_log WHERE userid = ? AND processname = ? AND `type` = ? AND description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @processname, @searchtype, @searchwords, @logstatus, @logstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
END  $$
--  -----------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercereservezyx987_getOrderdetailsList`(
   IN tablenameprefix varchar(200),
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN propertyvalueid int,    
   IN searchusername varchar(200), 
   IN minprice DECIMAL(15,2),
   IN maxprice DECIMAL(15,2),
   IN fromdate date,
   IN todate date,
   IN mystatus int,
   OUT ordertotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';

   set @tablenameprefix = tablenameprefix;
   if tablenameprefix = '' then set @tablenameprefix = 'wp_'; end if;
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @propertyvalueid = propertyvalueid;
   set @searchusername = CONCAT('%', searchusername, '%');
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   set @minprice = 0;  -- minprice;
   set @maxprice = 9999999999999;  -- maxprice;
   if minprice > 0 then set @minprice = minprice; end if;
   if maxprice > 0 then set @maxprice = maxprice; end if;  

   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 

   set @mystatus = -1;
   if mystatus > 0  then set @mystatus = mystatus; end if;
--  --------------------------------------
set @querypart1 = "Select o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.createtimeutc) 'createtimeutc', ";
set @querypart1 =  concat(@querypart1 , "  GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription' "
," ,opv.propertyvalueid, group_concat(pv.shownname, '(', opv.propertyvalueid,')') 'propertyvalueshownnameandid',group_concat(p.name, '(', p.id,')') 'productnameandid',group_concat(pr.shownname, '(', pr.id,')') 'propertyshownnameandid' "
," from wp_dragonecommercereservezyx987_order o  "
," LEFT JOIN wp_dragonecommercereservezyx987_order_propertyvalue opv ON o.id=opv.orderid "
," LEFT JOIN wp_dragonecommercereservezyx987_propertyvalue pv ON opv.propertyvalueid = pv.id "
," LEFT JOIN wp_dragonecommercereservezyx987_property pr ON pv.propertyid = pr.id "
," LEFT JOIN wp_dragonecommercereservezyx987_product p ON opv.productid = p.id " 
," LEFT JOIN "
, @tablenameprefix
,"users u ON o.userid = u.ID "
," LEFT JOIN wp_dragonecommercereservezyx987_product_order po  ON opv.orderid = po.orderid and opv.productid = po.productid and opv.propertyvalueids = po.productpropertyvalueids "
);

--  ---------------------------------------
set @querypart2 =  concat(" ( Select o.id from wp_dragonecommercereservezyx987_order o  "
," LEFT JOIN wp_dragonecommercereservezyx987_order_propertyvalue opv ON o.id=opv.orderid "
," LEFT JOIN wp_dragonecommercereservezyx987_propertyvalue pv ON opv.propertyvalueid = pv.id "
," LEFT JOIN wp_dragonecommercereservezyx987_property pr ON pv.propertyid = pr.id "
," LEFT JOIN wp_dragonecommercereservezyx987_product p ON opv.productid = p.id " 
," LEFT JOIN "
, @tablenameprefix
,"users u ON o.userid = u.ID "
," LEFT JOIN wp_dragonecommercereservezyx987_product_order po  ON opv.orderid = po.orderid and opv.productid = po.productid and opv.propertyvalueids = po.productpropertyvalueids ");

set @querypart3 = "  group by o.id, opv.propertyvalueid ";
--  -----------------------------------------------------------

    if searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;   
    
    
	if searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  and u.user_login LIKE ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  ---------------------------------------------------------------------------------------
   
    if searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus > 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;   
    
    
	if searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus > 0 && propertyvalueid <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
--  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
--  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&   

    if searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus <= 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
	if searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  and u.user_login LIKE ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus <= 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  ---------------------------------------------------------------------------------------
   
    if searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus > 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;   
    
    
	if searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  ' WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid ) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus > 0 && propertyvalueid > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', @querypart2,  " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  HAVING min(p.name) LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;

   SET ordertotalquantity = @ordertotalquantity;
--  =========================================================================================================================================================================================================================================
--  =========================================================================================================================================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0   then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus <= 0  && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0   then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0   then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id,orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  

    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVINGmin(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid <= 0   then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus > 0 && propertyvalueid <= 0   then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid <= 0   then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus > 0 && propertyvalueid <= 0   then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @sqlv = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid <= 0  then SET @statement = concat(@querypart1, " WHERE o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
--  ####################################################################################################################################################################################################################################################
--  ####################################################################################################################################################################################################################################################
--  ####################################################################################################################################################################################################################################################
--  ####################################################################################################################################################################################################################################################

    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus <= 0 && propertyvalueid > 0   then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus <= 0  && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus <= 0 && propertyvalueid > 0   then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus <= 0 && propertyvalueid > 0   then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id,orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  

    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  HAVING min(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVINGmin(p.name) like ? ORDER BY o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus > 0 && propertyvalueid > 0   then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus > 0 && propertyvalueid > 0   then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus > 0 && propertyvalueid > 0   then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus > 0 && propertyvalueid > 0   then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY o.id DESC, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY orderdetaildescription DESC,o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @sqlv = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid  ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0 && propertyvalueid > 0  then SET @statement = concat(@querypart1, " WHERE pv.id = ? and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? and u.user_login LIKE ? group by o.id, opv.propertyvalueid   HAVING min(p.name) like ? ORDER BY total DESC,o.id, orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @propertyvalueid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
END  $$

--  -----------------------------------------
CREATE PROCEDURE `wp_dragonecommercereservezyx987_getOrderExportList`(
   IN tablenameprefix varchar(200),
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN searchusername varchar(200), 
   IN minprice DECIMAL(15,2),
   IN maxprice DECIMAL(15,2),
   IN fromdate date,
   IN todate date,
   IN mystatus int,
   OUT ordertotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';

   set @tablenameprefix = tablenameprefix;
   if tablenameprefix = '' then set @tablenameprefix = 'wp_'; end if;
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchusername = CONCAT('%', searchusername, '%');
   set @minprice = 0;  -- minprice;
   set @maxprice = 9999999999999;  -- maxprice;
   if minprice > 0 then set @minprice = minprice; end if;
   if maxprice > 0 then set @maxprice = maxprice; end if;  

   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 

   set @mystatus = -1;
   if mystatus > 0  then set @mystatus = mystatus; end if;

    if searchwords = '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
	if searchwords = '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  ---------------------------------------------------------------------------------------
   
    if searchwords = '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
	if searchwords = '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
   SET ordertotalquantity = @ordertotalquantity;
--  ==========================================================================================================================
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus <= 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus <= 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  

    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus > 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus > 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus > 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus > 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc',  o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC ");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC "); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
END  $$
--  ------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercereservezyx987_getOrderList`(
   IN tablenameprefix varchar(200),
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN searchusername varchar(200), 
   IN minprice DECIMAL(15,2),
   IN maxprice DECIMAL(15,2),
   IN fromdate date,
   IN todate date,
   IN mystatus int,
   OUT ordertotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';

   set @tablenameprefix = tablenameprefix;
   if tablenameprefix = '' then set @tablenameprefix = 'wp_'; end if;
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchusername = CONCAT('%', searchusername, '%');
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   set @minprice = 0;  -- minprice;
   set @maxprice = 9999999999999;  -- maxprice;
   if minprice > 0 then set @minprice = minprice; end if;
   if maxprice > 0 then set @maxprice = maxprice; end if;  

   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 

   set @mystatus = -1;
   if mystatus > 0  then set @mystatus = mystatus; end if;

    if searchwords = '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
	if searchwords = '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  ---------------------------------------------------------------------------------------
   
    if searchwords = '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;
    
	if searchwords = '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
   SET ordertotalquantity = @ordertotalquantity;
--  ==========================================================================================================================
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus <= 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus <= 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  

    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus > 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus > 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus > 0   then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus > 0   then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc',  o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.discountfee) 'discountfee',min(o.couponfee) 'couponfee',min(o.description) 'description', min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercereservezyx987_order o JOIN wp_dragonecommercereservezyx987_product_order po ON o.id=po.orderid and o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercereservezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
END  $$
--  --------------------------------------------------
