tags:

views:

147

answers:

2

I am facing severe problem with JDBC ,converting string to integer.

String query = "Select F2, F3, F4 from myTable ORDER BY {fn  CONVERT(INT,F4)}" ;

error: Syntax error in ORDER By clause;

+1  A: 

The columns mentioned in the order by clause need to be exactly the same as they appear in the select clause. You should use the CONVERT function in the select clause as well. Also, you can reference selected columns by number to avoid repeating all that stuff:

SELECT f2, f3, CONVERT(INT, f4) FROM myTable ORDER BY CONVERT(INT, f4)

or

SELECT f2, f3, CONVERT(INT, f4) FROM myTable ORDER BY 3
jackrabbit
A: 

Not sure about JDBC, but the escape sequence in ODBC must be: {fn CONVERT(F4, SQL_INTEGER)}

da-soft