开发者

Max(Date) not working for varchar in SQL Server

I have a column 'TransactionDate' of Type 'varchar(15)' and i am trying to get the Max(TransactionDate) using this query

Select MAX(TransactionDate) from MyBank

The results are fine as long as Year is same (11/12/2010) but as soon as i put some data with year (12/23/2011) , the query still shows the Max. Date of 2010 instead of 2011.

My Data is as shown below

Name | Age | TransactionDate | Amount
John | 23  | 12/12/2010      | 2000
Rock | 24  | 12/23/2010      | 1000
Sa开发者_StackOverflow社区m  | 29  | 1/2/2011        | 5000
Nomi | 22  | 1/3/2011        | 6000

Although the query should return 1/3/2011 but its still returning 12/23/2010.

Thanking in Advance.


Change it to Max(cast(TransactionDate as DateTime))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜