Unify the ugly sql code in centralized var.