SELECT p.id products_id ,convert( qty.meta_value , UNSIGNED INTEGER)  products_quantity ,
sku.meta_value products_model,
'' products_image,
convert(spr.meta_value ,DECIMAL) products_price,
convert(sweight.meta_value ,DECIMAL) products_weight,
p.post_date products_date_added, 
p.post_modified products_last_modified, 
p.post_date products_date_available, 

0 products_status,
0 manufacturers_id, 
0  products_ordered,
0 products_tax_class_id,
p.post_title products_name 
 FROM  <@PREFIX>posts p
left join <@PREFIX>postmeta sku on sku.post_id = p.id
and sku.meta_key = '_sku'
left join <@PREFIX>postmeta qty on qty.post_id = p.id
and qty.meta_key = '_stock'

left join <@PREFIX>postmeta spr on spr.post_id = p.id and spr.meta_key = '_price'
left join <@PREFIX>postmeta sweight on sweight.post_id = p.id and sweight.meta_key = '_weight'


where post_type ='product' and post_status = 'publish'

and 99 <>  %s
and ((p.post_date >=  %s) and (p.post_modified is null or
p.post_modified =  00000000 ) or p.post_modified >= %s ) 
and ((p.post_date <=  %s) and (p.post_modified is null or 
p.post_modified =  00000000 ) or p.post_modified <= %s ) 
order by products_id
