Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Converting char to date and pulling past two years data

I need to pull data from tables with millions of rows and limit it to just the past two years. I am working on developing a SQL statement to enter into Power BI to limit what it pulls. Obviously I am a novice but I cannot figure this out and all suggested approaches are not working for me. It is also unclear to me how to convert, limit, and pull all of the data from this table.

The LOADED_DATE column is char(8) so first I used TO_DATE to convert it, as you can see, but I am not sure what I am missing.

SELECT TO_DATE(LOADED_DATE, 'YYYYMMDD')
FROM ELLIPSE.MSF26A
WHERE LOADED_DATE >= ADD_MONTHS(SYSDATE,-24)

SQL Error [1861] [22008]: ORA-01861: literal does not match format
string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are trying to compare a string to a date in the WHERE clause. Try this:

SELECT TO_DATE(LOADED_DATE, 'YYYYMMDD')
FROM ELLIPSE.MSF26A
WHERE TO_DATE(LOADED_DATE, 'YYYYMMDD') >= ADD_MONTHS(SYSDATE,-24)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading