Wednesday, August 18, 2010

How to find the maximum value among a list of alpanumeric characters in a database in asp.net query?

I have a database column ';AssetID'; with values like ser1.... ser9, ser10, ser11, met1, met2.etc I want an sql query which would retrieve me the highest value among the category ';ser'; i.e. it should get me the value ser11. If I use max(AssetID) in the query, I get only ser9 and not ser11. So how this is possible?How to find the maximum value among a list of alpanumeric characters in a database in asp.net query?
When you try to sort or pull a max value from a TEXT field, sorting won't be the same as a numeric field. A text sort will sort by ranking on a per character basis.





So, ser9 will be a ';higher'; value than ser11 because the function considers ';ser9'; higher than ';ser1xxxxxxxxx....';.





The Data Analyst - http://www.squidoo.com/thedataanalystHow to find the maximum value among a list of alpanumeric characters in a database in asp.net query?
Yes that is possible.you can use Compute(';MAX)





connection.Open();


OleDbCommand mycommand = new OleDbCommand();


mycommand.Connection = connection;


DataTable categories = GetDataTable(';categories';, ';SELECT * FROM categories';, connection);


string orders = categories.Compute(';MAX(id_category)';, ';';).ToString();

No comments:

Post a Comment