sqldatesnowflake-cloud-data-platformvarchar

How to convert varchar yyyy-mm to date


I have a column of data in the format of yyyy-mm that is VARCHAR(7). Using CONVERT doesn't work and I'm guessing it's because it needs a day in the string (yyyy-mm-dd), but I don't know how to add that to the string. I started with this code:

SELECT * FROM TABLE_X WHERE MONTH BETWEEN ('2022-06','2023-06')

Solution

  • How about:

    SELECT * 
    FROM TABLE_X 
    WHERE MONTH BETWEEN '2022-06' AND '2023-06'
    

    The comparisons between string will work, as the question states that "column of data in the format of yyyy-mm that is VARCHAR".