0

I want to use some function in Sort Expression of Datatable.Select.
I try by this-

string strSelect="";
///Some code
string strSort="RIGHT(TESTID,2) DESC,SUBSTRING (TESTID,3,5) DESC, TESTDATE DESC";
dtOld.Select(strSelect,strSort );

but,I think there is something wrong by using sql function(eg.SUBSTRING) in Sort Expression. SO, How can I sort my datatable by this sort expression? Is it possible?
Thanks.

nnnn
  • 1,041
  • 3
  • 18
  • 35
  • If there is impossible to use SUBSTRING in Datatable.Select,is there any other ways to do this problem?? – nnnn Jan 25 '13 at 02:13

2 Answers2

0

Do you get any error message?

Not sure that will do but you have a space after SUBSTRING, SHOULD BE SUBSTRING(...,,).

I tested below for mysql and SQL server 2012 and it works:

SELECT SUBSTRING('AAA BBBCCC',3,5);

Result: A BBB
Anda Iancu
  • 530
  • 1
  • 3
  • 9
0
string strSelect="RIGHT(TESTID,2) AS T1, SUBSTRING(TESTID,3,5) AS T2";
///Some code
string strSort="T1 DESC, T2 DESC, TESTDATE DESC";
dtOld.Select(strSelect, strSort);
Anda Iancu
  • 530
  • 1
  • 3
  • 9