Updates of sql for new base
More corrections to code cause of db changes