Question: Whenever i am selecting any attribute or make any change in a product and try to save it in my magento store backend i am getting following error. 

```
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ) AND (p.entity_id = '1696') LIMIT 1' at line 3, query was: SELECT DISTINCT p.entity_id FROM `catalog_product_entity` AS `p` INNER JOIN `catalog_product_flat_1` AS `cpf` ON cpf.entity_id = p.entity_id LEFT JOIN `catalog_category_product` AS `ccp` ON ccp.product_id = p.entity_id WHERE ( () ) AND (p.entity_id = '1696') LIMIT 1

```

Kindly let me know what is causing this error and how i can resolve this.

Answer: 
I don't have a solution but I have a place you can start debugging.  

The query looks very similar to the one generated by the method `Mage_Rule_Model_Resource_Abstract::getProductFlatSelect()` 

```
public function getProductFlatSelect($storeId, $condition)
{
    $select = $this->_getReadAdapter()->select();
    $select->from(
            array('p' => $this->getTable('catalog/product')),
            array(new Zend_Db_Expr('DISTINCT p.entity_id'))
        )
        ->joinInner(
            array('cpf' => $this->getTable('catalog/product_flat') . '_' . $storeId),
            'cpf.entity_id = p.entity_id',
            array()
        )->joinLeft(
            array('ccp' => $this->getTable('catalog/category_product')),
            'ccp.product_id = p.entity_id',
            array()
        );

    $where = $condition->prepareConditionSql();
    if (!empty($where)) {
        $select->where($where);
    }

    return $select;
}

```

For some reason (unknown to me) the `$where` variable does not come up as empty, but it comes up as `()` or `(())`.  

`$where` is generated either by `Mage_Rule_Model_Condition_Product_Abstract::prepareConditionSql()` (but I doubt it in your case, but it still could be it) either `Mage_Rule_Model_Condition_Combine::prepareConditionSql()` (my money is on this one). 

This last one looks like this: 

```
public function prepareConditionSql()
{
    $wheres = array();
    foreach ($this->getConditions() as $condition) {
        /** @var $condition Mage_Rule_Model_Condition_Abstract */
        $wheres[] = $condition->prepareConditionSql();
    }

    if (empty($wheres)) {
        return '';
    }
    $delimiter = $this->getAggregator() == "all" ? ' AND ' : ' OR ';
    return ' (' . implode($delimiter, $wheres) . ') ';
}

```

This means that when a product is saved, the catalog rules are indexed to see if the product matches the criteria.  

And for each rule, the conditions are parsed recursively (if a condition is a group of other conditions the method is called again).  

But for some reason your `$wheres` array is empty, but it acts like it's not empty. 

That's all I have for now.  

I would start investigating from the points I mentioned above. Also check if you have some extension that might affect the catalog rules.  

Or maybe you had an extension and disabled it, but the rules that were already there still think that extension exists.
Check your Catalog Rules,
probably you have promotion rule condition without an argument.

For example

Category in (empty)