Hi,
I'm attempting to query an Oracle Database through a VBA module in my Access DB. Within the query, I'm trying to use CASE WHEN..THEN..ELSE to evaluate a particular column.
If I login to this Oracle Database using TOAD, the "CASE WHEN.." syntax shown below works perfectly.
Code:
SELECT SG_DESCRIPTION, CON_DESCRIPTION,
CASE WHEN ASI_AA_LEVEL = 'E' THEN 'Enabled' ELSE 'Disabled/Nd Open Clt' END as SCREEN_STATUS
FROM MYTABLE
However, I'm having trouble translating that into my VBA module. I keep receiving a "Missing Expression" error when trying to run the querydef, so I must be missing something in my syntax but can't seem to figure out where I'm going wrong, e.g.:
Code:
strSQL = "SELECT SG_DESCRIPTION, CON_DESCRIPTION," & _
" CASE WHEN ASI_AA_LEVEL = 'E' THEN 'Enabled' ELSE 'Disabled/Nd Open Clt' END as SCREEN_STATUS," & _
" FROM MYTABLE"
Within the VBA module, I have the SQL Query defined in a string variable and then creating a querydef with a connection to an Oracle Database (the connection string is defined under strConnect)
Code:
Dim db As DAO.Database
Dim qdef As DAO.QueryDef
Dim strSQL As String
Dim strConnect As String
strConnect = "<Connection String for ODBC>"
Set db = CurrentDb
Set qdef = db.CreateQueryDef("MyQuery")
With qdef
.Connect = strConnect
.SQL = strSQL
.ReturnsRecords = True
End With