Bash Nested Case Statement Sql Syntax