Convert INT to VARCHAR SQL

2019-01-21 01:41发布

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 ?

3条回答
霸刀☆藐视天下
2楼-- · 2019-01-21 01:56

You can use CAST function:

SELECT CAST(your_column_name AS varchar(10)) FROM your_table_name
查看更多
Summer. ? 凉城
3楼-- · 2019-01-21 01:57

Use the STR function:

SELECT STR(field_name) FROM table_name

Arguments

float_expression

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

length

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

decimal

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楼-- · 2019-01-21 02:11

Use the convert function.

SELECT CONVERT(varchar(10), field_name) FROM table_name
查看更多
登录 后发表回答