SQL case indexes

#3329
Need to add test for indices