mdomba there is a problem with your solution in a particular situation:
I would like to use CSqlDataProvider and how would I get the totalItemCount since the sql statement is executed when the CSqlDataProvider object is created ?
In both my solution and yours I have to execute the same sql statement ONE more time before the
new CSqlDataProvider($sql, array( ... )
Any other more efficient way provided by Yii framework?
Note: in documentation is saying that is mandatory to provide the totalItemCount in order to get correct pagination