简体   繁体   English

如何修复 SQL 错误“将数据类型 varchar 转换为数字时出错”?

[英]How to fix the SQL error "Error converting data type varchar to numeric"?

I am selecting records from a SQL Server database but result says that the query completed with errors and then error I get is我正在从 SQL Server 数据库中选择记录,但结果表明查询完成时出现错误,然后我得到的错误是

Error converting data type varchar to numeric将数据类型 varchar 转换为数字时出错

In my query I am fetching records based on particular codes and then I use the = the query fails but using <> the query runs.在我的查询中,我根据特定代码获取记录,然后使用=查询失败但使用<>查询运行。 Can anyone assist me where I am doing it wrong because I looked for solutions provided they are not working for me.任何人都可以在我做错的地方帮助我,因为我正在寻找解决方案,前提是它们对我不起作用。

I am sharing by query below我通过下面的查询分享

SELECT
    MAX(amount) AS amount, 
    MAX(date_of_payment) AS date_of_payment, 
    MAX(customer) AS customer, 
    MAX(payment_type) AS payment_type, 
    MAX(currency) AS currency, 
    MAX(PayCtrNum) AS PayCtrNum, 
    MAX(TRACKING_NO) AS TRACKING_NO, 
    MAX(Payment_id) AS Payment_id 
FROM 
    PAYMENTS_VW 
WHERE 
    date_of_payment = '21/01/2020' 
    AND account_code = '440342' 
GROUP BY 
    Payment_id

I have used CAST and changed the column to Int it is working now.我已经使用 CAST 并将列更改为 Int 它现在正在工作。 The query now reads查询现在读取

SELECT max(amount) as amount, 
max(date_of_payment) as date_of_payment, 
max(customer) as customer, 
max(payment_type) as payment_type, 
max(currency) as currency, 
max(PayCtrNum) as PayCtrNum, 
max(TRACKING_NO) as TRACKING_NO, 
max(Payment_id) as Payment_id 
FROM PAYMENTS_VW 
WHERE date_of_payment = '21/01/2020' 
AND CAST(account_code AS int) = '440342' 
GROUP BY Payment_id

And it is working它正在工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在SQL中将数据类型varchar转换为数字时出错 - Error converting data type varchar to numeric in SQL SQL - 将数据类型varchar转换为数字时出错 - SQL - Error converting data type varchar to numeric SQL Server 2012将数据类型varchar转换为数值时出错 - SQL Server 2012 Error converting data type varchar to numeric 在sql server中将数据类型varchar转换为数字时出错 - Error converting data type varchar to numeric in sql server 在SQL Server 2008中将数据类型varchar转换为数值时出错 - Error converting data type varchar to numeric in sql server 2008 在SQL Server中将varchar转换为数据类型数值的算术溢出错误 - Arithmatic overflow error converting varchar to data type numeric in sql server SQL Server:将数据类型varchar转换为数值时出错 - SQL Server: error converting data type varchar to numeric 在SQL Server中将varchar转换为数值类型的算术溢出错误 - Arithmetic overflow error converting varchar to data type numeric in SQL Server 将varchar转换为数字:将数据类型varchar转换为数字时出错 - varchar to numeric:Error converting data type varchar to numeric 如何解决SQL Server中的“将varchar转换为数据类型数值的算术溢出错误”错误? - How to solve “Arithmetic overflow error converting varchar to data type numeric” error in sql server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM