k.horde k.horde - 1 year ago 69
SQL Question

SQL how to pull out data which has commas without them?

In the database there is date put into fields with commas like

which stands for date

I need to take out the date and filter it so that I have only records from a period of time.

Do you know how I can pull out the data without the commas so I have integers which I can compare then?

Answer Source

Remove the commas using REPLACE, and then convert to a date using TIMESTAMP_FORMAT and DATE:



SELECT DATE(TIMESTAMP_FORMAT(REPLACE('20,151,112', ',', ''), 'YYYYMMDD')) AS "theDate"
FROM yourTable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download