Last morning, my manager gave me a new database where I had to write few SQL Stored procedures. There was a column MMs which was meant for numeric values so I had the understanding that Sql Function MAX will work on it. But this was not the case.
It was a varchar column holding numeric values randomly stored from 1 to 41. I was assuming that my SQL Statement: “SELECT MAX(MMS) FROM tbl” will give me 41 as the result but it came out to be 9.
Later I invested that MAX when used with string datatypes takes the first numeric letter from the column and then gives the MAX out of them.
Does anybody has the idea why it is happening?
From here:
http://msdn.microsoft.com/en-uk/library/ms187751.aspx
If you want to sort the contents of your column numerically, you can do something like: