SQL encoding

Fix bug in SQL encoding