Running a SELECT statement against multiple tables and I need to filter the data down to the last 24 hours. The column i am running the date filter against is called service_date and the date format it uses is YYYYMMDD. I have tried many options and either get a syntax error, invalid date parameter error, or it runs and doesn't really limit it to the last 24hours. Here is my statement with no filter on service date:
SELECT provider_mstr.description, location_mstr.location_name, person.first_name, person.last_name,
person.date_of_birth, patient_procedure.service_item_id, patient_procedure.service_item_desc,
patient_procedure.service_date, patient_procedure.diagnosis_code_id_1, payer_mstr.payer_name,
patient_encounter.enc_timestamp
FROM patient_procedure INNER JOIN person
ON person.person_id = patient_procedure.person_id
INNER JOIN payer_mstr
ON patient_procedure.payer_id = payer_mstr.payer_id
INNER JOIN provider_mstr
ON patient_procedure.provider_id = provider_mstr.provider_id
INNER JOIN location_mstr
ON patient_procedure.location_id = location_mstr.location_id
INNER JOIN patient_encounter
ON patient_procedure.enc_id = patient_encounter.enc_id
WHERE payer_name LIKE '%Medicare%' OR payer_name LIKE '%Medicaid%' AND service_date ____________
ORDER BY provider_mstr.description
I have tried the following and failed:
service_date >= DATEADD(day, DATEDIFF(day, 1, CURRENT_TIMESTAMP), 0)
service_date <= CONVERT (date, getdate())