What is the correct syntax for using CASE WHEN and MAX() in an SQL Query in SPSS?
I've tried using the following query in the SPSS syntax window but it does not recognize either:
SELECT * FROM
(
SELECT id, MAX(CASE WHEN val='A' THEN 'A' END) as Val_1,
MAX(CASE WHEN val='B' THEN 'B' END) as Val_2
FROM table1 GROUP BY id
)a
WHERE Val_1 IS NULL OR Val_2 IS NULL;
I'm using SPSS 20.
Update: I tried using both my query and the one presented by AK47.
My query's error:
Warning. Command name: GET DATA SQLExecDirect failed :[Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'MAX(CASE WHEN val='A' THEN 'A' END)'
AK47's Error:
Warning. Command name: GET DATA SQLExecDirect failed :[Microsoft][ODBC Excel Driver] Syntax error in FROM clause.
Is this all a matter of finding the correct syntax in SPSS or do you think SPSS just doesn't support some SQL functions?
GET DATAstatement from the SPSS syntax? - djhurio