I've the following table, where `order_date` and `delivery_date` is of type 'varchar'

```
id      name        order_date      delivery_date
---------------------------------------------------------
1       A           04/01/2017      04/08/2017
2       B           04/01/2017      NULL
3       C           04/02/2017      04/03/2017
4       D           04/04/2017      04/05/2017
5       E           04/05/2017      04/11/2017
6       F           04/11/2017      NULL
7       G           04/15/2017      04/17/2017
8       H           04/18/2017      NULL

```

I need all the records which have 

```
* delivery_date between 04/01/2017 TO 04/15/2017
* if delivery_date IS NULL then check order_date between 04/01/2017 TO 04/15/2017
    (in this case order_date is assumed as delivery_date)

```

I'm trying this code :

```
SELECT *,
IF(delivery_date IS NOT NULL, `delivery_date`, `order_date`) as `final_date`
FROM `test` 
WHERE STR_TO_DATE(`final_date` ,'%m/%d/%Y') BETWEEN STR_TO_DATE('04/01/2017','%m/%d/%Y') AND STR_TO_DATE('04/15/2017','%m/%d/%Y')

```

But is is giving this error :

```
Unknown column 'final_date' in 'where clause'

```