I am using Sybase and I am doing a select which returns me a column called "iftype", but its type is int and I need to convert into varchar. When I try to do the select without the convert function I get this error:

Error code 257, SQL state 37000: Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. Use the CONVERT function to run this query.

I dont know how to implement the function CONVERT. Can anyone help me, please ?


Use the convert function.

SELECT CONVERT(varchar(10), field_name) FROM table_name
  • 8
    According to the error, it's VARCHAR to INT but I'm answering his question, not the error message. – Tobberoth Nov 14 '13 at 14:07
  • 2
    Thanks. But now I got another error. When I try to do this kind of Select : SELECT CONVERT(varchar(10), field_name) FROM table_name. Or even the normal one like: SELECT field_name FROM table_name. Both are correct. I dont know why. But when I try to but a "where" at the end of the select, using the convert or not, I get the same error: Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. Use the CONVERT function to run this query – Murilo Nov 14 '13 at 14:09
  • 3
    @Murilo That's because the error is not from what you think. The error tells you that your code is trying to use a varchar where an int is needed. You need write your actual SQL statement for us to help you. – Tobberoth Nov 14 '13 at 14:10
  • 14
    @Tobberoth, for what it's worth, I just landed here by googling. Part of SO's value is getting answers to almost any question, even basic ones. – KyleMit Apr 8 '14 at 19:58
  • 7
    I think it should be varchar(11) in case the number is a large negative number. – Trisped Aug 25 '14 at 22:36

Use the STR function:

SELECT STR(field_name) FROM table_name



Is an expression of approximate numeric (float) data type with a decimal point.


Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.


Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.

source: https://msdn.microsoft.com/en-us/library/ms189527.aspx

  • 4
    STR() should be the correct answer, it's simpler and less error-prone than the alternatives. – HerrimanCoder Nov 4 '17 at 23:01
  • 8
    For some strange reason, this didn't work for me as it was adding a tab in front of the text, no idea why. Selected solution did work though. – MaQy Nov 23 '17 at 19:27
  • 3
    str pads spaces on the front of the converted number making it useless – m12lrpv Apr 18 '18 at 1:20
  • 15
    Use LTRIM(STR()) – ashilon Nov 28 '18 at 13:08
  • 2
    STR() gives whitespaces on the front of the variable you convert to string. It can be a good choise to convert decimal variables but not for Int. – Ebleme Feb 27 '19 at 10:38

You can use CAST function:

SELECT CAST(your_column_name AS varchar(10)) FROM your_table_name

Actually you don't need to use STR Or Convert. Just select 'xxx'+LTRIM(ColumnName) does the job. Possibly, LTRIM uses Convert or STR under the hood.

LTRIM also removes need for providing length and usually default 10 is good enough for integer to string conversion.

SELECT LTRIM(ColumnName) FROM TableName

CONVERT(DATA_TYPE , Your_Column) is the syntax for CONVERT method in SQL. From this convert function we can convert the data of the Column which is on the right side of the comma (,) to the data type in the left side of the comma (,) Please see below example.


SELECT cast(CAST([field_name] AS bigint) as nvarchar(255)) FROM table_name

Your Answer

