Using a date to get last months records?

kawi6rr

Registered User.
Local time
Today, 13:04
Joined
Jun 29, 2010
Messages
28
I'm running the query below to get a list but when I add the date function I get this error. The date function is supposed to
get all the records that have been added in the last month.

ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Error at Line: 25 Column: 75

I know this works in MS Access but I can't get it to work in Oracle SQL Developer, limited SQL skills.

Can you please help me with where I'm going wrong? I've bolded the date function below in my code.

SELECT DISTINCT HOSP.PAT_ENC_CSN_ID,
HOSP.PAT_CLASS_C,
HOSP.DEPARTMENT_ID,
HOSP.DEPARTMENT_NAME,
HOSP.HSP_ACCOUNT_ID,
HOSP.CONTACT_DATE,
HOSP.HOSP_ADMSN_EFFECTIVE_TIME,
HOSP.ADMIT_PROV_ID,
HOSP.DISCH_PROV_ID,
HOSP.HOSP_DISCH_TIME,
HOSP.PAT_ID,
HOSP.PATIENT_MRN_NUM,
EDG.DX_ID,
EDG.DX_NAME,
EDG.ICD9_CODE,
SER.PROV_NAME,
DXL.LINE
FROM OPS$HIDBA.HOSPITALIZATION HOSP
INNER JOIN HC_ADM.HC_HSP_ACCT_DX_LIST DXL ON HOSP.HSP_ACCOUNT_ID = DXL.HSP_ACCOUNT_ID
INNER JOIN HC_ADM.HC_CLARITY_EDG EDG ON DXL.DX_ID = EDG.DX_ID
INNER JOIN HC_ADM.HC_CLARITY_SER SER ON HOSP.DISCH_PROV_ID = SER.PROV_ID
WHERE ICD9_CODE like ('767.0%') OR ICD9_CODE like ('767.1%') OR ICD9_CODE like ('767.2%')
OR ICD9_CODE like ('767.3%') OR ICD9_CODE like ('767.4%') OR ICD9_CODE like ('767.5%')
OR ICD9_CODE like ('767.6%') OR ICD9_CODE like ('767.7%') OR ICD9_CODE like ('767.8%')
OR ICD9_CODE like ('767.9%') And DateDiff ("m", (HOSP.HOSP_DISCH_TIME), Date()) < 1
ORDER BY ICD9_CODE;

Thanks!!
 
Last edited:
Can't speak for Oracle, but the SQL Server equivalent of the Date() function is GETDATE(). Actually that's the equivalent of Now(). If you just want the date:

CONVERT(varchar, GETDATE(), 101)

Also, I think SQL Server will want single quotes instead of double quotes.
 

Users who are viewing this thread

Back
Top Bottom