將INT轉換爲VARCHAR SQL

本文翻譯自: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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章