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.

1
  • If there is impossible to use SUBSTRING in Datatable.Select,is there any other ways to do this problem?? Commented Jan 25, 2013 at 2:13

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

I want to use this SUBSTRING() in Sort Condition but it is wrong.
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);

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.