[英]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.