Question: How to get the data from sql using Date, I'm using the date datatype as varchar, I want to fetch the record from sql table. I want to fetch the last month data, for eg today date is 04/11/2014. From today minus one month 04/10/2014 so I want to search by this date 04/10/2014

I have tried this query.

```
SELECT * 
FROM [IndxRpt] 
WHERE EcrCylinderNo IS NULL 
  AND OrderDate <= '04/10/2014'

```

And also I tried this:

```
SELECT * 
FROM [IndxRpt] 
WHERE EcrCylinderNo IS NULL 
  AND OrderDate <= (CONVERT(VARCHAR(50), '04/10/2014', 103)) 

```

But its showing the November month data also. How to get this?

Answer: 
Rationaly you should use OrderDate as DateTime data type. But still answering your question you need to cast OrderDate in Datetime Datatype and than apply any logical operation on it for filtration in WHERE condition.

So, your query will as:

```
SELECT * 
FROM [IndxRpt] 
WHERE EcrCylinderNo IS NULL 
AND CONVERT(DATETIME,OrderDate,103) <= CONVERT(DATETIME,'04-OCT-2014',103)

```
If for some reason you cannot change the column to a proper data type i would suggest converting it to datetime for your query.

E.G. 

```
SELECT * 
FROM [IndxRpt] 
WHERE EcrCylinderNo IS NULL 
  AND CAST(OrderDate as DateTime)<=  '04/10/2014'

```