0

Trying to sort records using ORDER BY in vb.net but I am not getting the required result. I am fetching records from two different tables but sorting use a column from a single table.

CODE

'query data
    Dim cmd As OleDbCommand = New OleDbCommand("SELECT biodata_info.student_id, sname, mname, fname, passport, " & _
                            " result_score FROM biodata_info LEFT JOIN [" & connResultLink & "].result_summary ON biodata_info.student_id = result_summary.student_id " & _
                            "WHERE result_term = @resultTerm  AND result_session = @resultSession AND result_class = @resultClass AND result_arm = @resultArm " & _
                            " ORDER BY result_summary.result_score ASC", connStudent)

    cmd.Parameters.AddWithValue("@resultTerm", term1)
    cmd.Parameters.AddWithValue("@resultSession", session1)
    cmd.Parameters.AddWithValue("@resultClass", className1)
    cmd.Parameters.AddWithValue("@resultArm", armName1)

RESULT using ASC

<1> 1011
<2> 863
<3> 911
<4> 985

RESULT using DESC

<1> 985
<2> 911
<3> 863
<4> 1011
6
  • Possible duplicate of stackoverflow.com/questions/489874/sql-order-chars-numerically Commented Jul 21, 2015 at 8:29
  • 1
    Seems to me like your result_summary.result_score column is not a numeric data type, but a string data type. try using CInt(result_summary.result_score) in the order by clause. Commented Jul 21, 2015 at 8:31
  • @ZoharPeled Thanks, that's so true. Thanks once more. Commented Jul 21, 2015 at 8:34
  • 3
    @BlackPearl: but it would be much better to use the correct datatype in the first place. Commented Jul 21, 2015 at 8:35
  • @TimSchmelter cInt in ms-access... Commented Jul 21, 2015 at 8:35

2 Answers 2

2

Seems to me like your result_summary.result_score column is not a numeric data type, but a string data type. try using CInt(result_summary.result_score) in the order by clause.

Read this link about type conversions in ms-access (and other office products)

Sign up to request clarification or add additional context in comments.

Comments

1

if 'result_score' is a string field use cast(result_score as Unsigned) . But if 'result_score' is a numeric field and still you are not getting result in ascending order, try abs(result_score).

Hope this will help.

Comments

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.