My database table: (Purchase-Details)

Table with value:

I want to find out the list of upcoming exipry medicines.
my Query:
SELECT * FROM PURCHASE_DETAILS
WHERE CONVERT(date,EXPIRY) BETWEEN CONVERT(DATE,'21-Dec-2021') AND CONVERT(DATE,'31-Oct-2022')
but error occur.
Please suggest me.
Nitin SontakkePosted Dec 23, 2021, 11:24 AM
To begin with, not sure why the dates are being stored as nvarchar. Not a very good practise, I would say.
Anyway.
Because value stored in [Expirty] column is not a valid date, I will have to assume that it is First of every month. Calculating last day of given month in column would be complicated if not impossible.
I propose following:
select *
from [dbo].[purchase_details]
where convert(date, '01-' + [Expiry]) between convert(date, '21-Dec-2021') and convert(date, '31-Oct-2022')
Hope it helps!
Srinivasan RamamoorthiPosted Dec 24, 2021, 9:33 AM
Sachin SinghPosted Dec 21, 2021, 6:15 PM
Satya KarkiPosted Dec 21, 2021, 6:52 AM
Rajanikant HawaldarPosted Dec 21, 2021, 4:19 AM