Gettings SQL conversion to work