将INT转换为VARCHAR SQL

本文介绍了在Sybase环境中遇到的一个问题,即在SQL查询中需要将INT类型的“iftype”列转换为VARCHAR类型。作者在尝试不使用转换函数时遇到了错误,错误提示不允许隐式转换。解决方案是使用CONVERT函数,但具体实现方法不清楚。评论区提供了使用CONVERT函数的参考和详细说明,包括转换函数的参数如长度和小数位数。
摘要由CSDN通过智能技术生成

本文翻译自:Convert INT to VARCHAR SQL

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. 我正在使用Sybase,我正在做一个select,它返回一个名为“iftype”的列,但它的类型是int,我需要转换为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. 错误代码257,SQL状态37000:不允许从数据类型“VARCHAR”到“INT”的隐式转换。 Use the CONVERT function to run this query. 使用CONVERT函数运行此查询。

I dont know how to implement the function CONVERT . 我不知道如何实现CONVERT函数。 Can anyone help me, please ? 有人可以帮帮我吗?


#1楼

参考:https://stackoom.com/question/1LpaW/将INT转换为VARCHAR-SQL


#2楼

使用转换功能。

SELECT CONVERT(varchar(10), field_name) FROM table_name

#3楼

Use the STR function: 使用STR功能:

SELECT STR(field_name) FROM table_name

Arguments 参数

float_expression 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. 默认值为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. decimal必须小于或等于16.如果decimal小于16,则结果将被截断为小数点右侧的16位。

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


#4楼

您可以使用CAST功能:

SELECT CAST(your_column_name AS varchar(10)) FROM your_table_name
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值