How to convert varchar yyyy-mm to date

96 views Asked by At

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')
1

There are 1 answers

0
Felipe Hoffa On BEST ANSWER

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".