KCINFR-979: fixing sql