SELECT CASE WHEN COALESCE(SUM(c), 0) = 0 THEN 1 ELSE 0 END AS ok
FROM (
  SELECT COUNT(*) c FROM dwd_material_readiness WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM dwd_material_shortage WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM dwd_s4_purchase_execution WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM dwd_supplier_risk WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM mdp_std_purchase_order WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM mdp_std_purchase_receipt WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM mdp_std_production_issue WHERE tenant_id IN (0, 1300000000001)
  UNION ALL SELECT COUNT(*) FROM mdp_std_s6_report WHERE tenant_id IN (0, 1300000000001)
) x;
