Quote identifiers in scopes

Used identifier quoting to prevent SQL issues and also cahnged case of SQL syntax to uppercase to match rails.