1
SELECT EM.rec_id AS rec_id,EM.employee_code, EM.employee_name, EM.designation,   EM.weekly_off_day, EM.gender, EM.payment_type, SM.shift_name, PM.plant_name, EM.status AS status,EM.settlement_no,
    SCM.section_name
    FROM employee_master AS EM 
    INNER JOIN shift_master AS SM ON EM.shift_rec_id = SM.rec_id 
    INNER JOIN section_master AS SCM ON EM.section_rec_id = SCM.rec_id 
    INNER JOIN plant_master AS PM ON EM.plant_rec_id = PM.rec_id
    ORDER BY CAST(EM.employee_code As INT) 

This is the sql I am using. Thanks

Praveen Prasannan
  • 6,970
  • 10
  • 50
  • 70
curiousguy
  • 2,980
  • 7
  • 34
  • 62

3 Answers3

2
SELECT EM.rec_id AS rec_id,EM.employee_code, EM.employee_name, EM.designation,   EM.weekly_off_day, EM.gender, EM.payment_type, SM.shift_name, PM.plant_name, EM.status AS status,EM.settlement_no,
    SCM.section_name
    FROM employee_master AS EM 
    INNER JOIN shift_master AS SM ON EM.shift_rec_id = SM.rec_id 
    INNER JOIN section_master AS SCM ON EM.section_rec_id = SCM.rec_id 
    INNER JOIN plant_master AS PM ON EM.plant_rec_id = PM.rec_id
    ORDER BY CAST(EM.employee_code As UNSIGNED ) 

See this SO thread

Community
  • 1
  • 1
Praveen Prasannan
  • 6,970
  • 10
  • 50
  • 70
1

Looking at the manual for CAST, INT is not a type you can cast to. However, you can cast to SIGNED or UNSIGNED. Assuming you want the integer to be unsigned, use;

ORDER BY CAST(EM.employee_code As UNSIGNED) 
Joachim Isaksson
  • 170,943
  • 22
  • 265
  • 283
1

The correct syntax should be one of the following:

CAST(EM.employee_code AS UNSIGNED INTEGER)
CAST(EM.employee_code AS SIGNED INTEGER)
CAST(EM.employee_code AS UNSIGNED)
CAST(EM.employee_code AS SIGNED)

Contrary to other languages where the signed and unsigned modifiers are optional, in this case the keyword INTEGER is the one that is optional.