[英]How to solve “Arithmetic overflow error converting varchar to data type numeric” error in sql server?
My query gets data from two tables and join them to give output as a single output. 我的查询从两个表中获取数据,并将它们联接在一起以将输出作为单个输出提供。 Subquery works without any error. 子查询可以正常工作。 But when i run the whole query i get an error like this. 但是,当我运行整个查询时,会出现这样的错误。
Arithmetic overflow error converting varchar to data type numeric. 将varchar转换为数值数据类型的算术溢出错误。
This is my query 这是我的查询
SELECT a.REF_NO + ' - '
+ (SELECT DISTINCT ( c.c_name )
FROM C_MASTER c,
A_MASTER a
WHERE a.c_no = c._NO) AS refer
FROM [A_MASTER] a,
[C_MASTER] c
WHERE a.c_no = c._no
ORDER BY a.REF_NO
REF_NO is numeric data type. REF_NO是数字数据类型。
Try this: 尝试这个:
select CAST(a.REF_NO AS VARCHAR(100))
+' - '
+(select distinct (c.c_name) from C_MASTER c, A_MASTER a
where a.c_no=c._NO) as refer
from [A_MASTER] a, [C_MASTER] c
where a.c_no=c._no
order by a.REF_NO
Overall this looks like a sloppy query to me, but I can't improve upon it without more explanation about what you're trying to do, what you want your results to look like, and what your tables look like. 总体而言,这对我来说似乎是一个草率的查询,但是如果没有更多关于您要执行的操作,想要的结果显示的内容以及表的显示形式的解释,我将无法对其进行改进。 Also, is there a reason you aren't using joins? 另外,您是否不使用联接是有原因的吗?
Try out with the below query. 尝试以下查询。 Use a join instead of separating tables with comma when writing queries. 编写查询时,请使用联接而不是用逗号分隔表。
Select distinct cast(a.ref_no as VARCHAR(50))+'-'+c.c_name
from C_MASTER c
Join A_MASTER a
On a.c_no=c._NO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.