Fixed a bug when categories was set
Updated SQL for K2