I have successfully converted a date stored as varchar to a valid date, and now need to use it in a dynamic date statement in my Where clause. Unfortunately, I keep getting errors, or no returns. The code below runs but I get no returns, if I put a static date in, it works, and if I use the "to_date(a.sold_dt,'YYYYMMDD')" in the where clause it errors out.
select
to_date(a.sold_dt,'YYYYMMDD') as Sold_dt,
a.BUYER_ZIP_CD,
b.Statename,
b.dmaname,
COUNT(VIN) VIN_COUNT
from MyTable a
join OtherTable b
on a.Buyer_Zip_cd = b.zipcode
where sold_dt >= (Current_Date() -92)
or sold_dt (between (current_date() -457) and (current_date() - 367))
and sale_type = 'Retail'
group by 1,2,3,4