You need to wrap any string literal in quotes. When using a dynamic query, you must also escape them.
'... WHERE SObjectType = \'Case\''
// missing: ^^ ^^
Or you could also rewrite that as:
String caseType = '\'Case\'';
// wrap in quotes! ^^ ^^
String soql = 'SELECT DeveloperName FROM RecordType WHERE SObectType = ' + caseType;
Or better yet, use merge variables:
String sObjectType = 'Case';
String soql = 'SELECT DeveloperName FROM RecordType WHERE SObjectType = :caseType';
As written, your current query would be the same as:
SELECT DeveloperName FROM RecordType WHERE SObjectType = Case
This query is obviously invalid. As stated above, the filter value needs to be wrapped in single quotes (as you do in the static version you include in the question).
A couple asides:
- The query language is named SOQL, not SQL.
- You should always favor static queries over dynamic when they are viable.
- When merging in strings provided by a user, make sure you escape single quotes to avoid injection vulnerabilities.