SELECT   
  p.code sku_style_10_left
, (p.NAME) title_style_45_left
,p.description as Description_style_25_left
,(ifnull( pi.qty_in_stock,0))   on_hand_qty_sum_6_style_20_right  
 

,  p.category_id
,tbl_productcategory.category


FROM      tbl_products p
inner join tbl_productcategory on tbl_productcategory.productCategory_id = p.category_id
LEFT JOIN  tbl_inventory pi
ON         p.product_id=pi.product_id
where (({available_stock} = 1 and ifnull( pi.qty_in_stock,0) > 0 ) or ({available_stock} = 0))
and ( p.category_id = case when  {category_id} = 0 then 1 else   {category_id} end )
 
and ( p.code like case when  ltrim(rtrim('{product_code}' ))= '0' then p.code else CONCAT(  ltrim(rtrim( ' {product_code} ')) , '%' )end )

ORDER BY   p.category_id,p.NAME,
             p.code



-- **********************************************************************
--  on_hand_qty_sum_6_style_20_right 
-- on_hand_qty = column name
-- _sum_ = this column values get sum

--  ** _style_20_right = td/th styles   ** mandatory **
-- 20 = td/th width 
-- right = text align     left/right/center