I don't know why your code didn't work, but I can give you a alternative that does not involve sql queries. Doing sql queries directly on Magento is very dangerous.
most probably you still have empty values because your query has where value !=''
. So your query skips the empty values.
Let's say your attribute code is custom_attribute
.
First you need to identify your products.
$collection = Mage::getModel('catalog/product')->getCollection();
//add filters to the collection here.
//for example if you still want all the products for which the attribute custom_attribute is not empty you can uncomment the line below
//$collection->addAttributeToFilter('custom_attribute', array('neq'=>''));
Now loop through the collection and update the attribute with your desired values:
$index = 400100;
foreach ($collection as $product) {
Mage::getSingleton('catalog/product_action')->updateAttributes(
array($product->getId()), //products to update
array('custom_attribute'=>$index), //attributes to update
0 //store view id
);
$index++;
}
When you are done clear the cache and reindex everything.