将varchar值'...'转换为数据类型int时转换失败

时间:2022-04-14 08:49:52

This is the error I get when trying to run this query:

这是我在尝试运行此查询时遇到的错误:

Conversion failed when converting the varchar value '307 307 307' to data type int.

将varchar值'307 307 307'转换为数据类型int时转换失败。

Query:

select count(sd.mrid)
    ,replace(replace(substring(sd.mrref_to_mr, charindex('l', sd.mrref_to_mr), len(sd.mrref_to_mr)), 'l', ''), 'x10', '')
where sd.mrref_to_mr like '%x10'
group by replace(replace(substring(sd.mrref_to_mr, charindex('l', sd.mrref_to_mr)), 'l', ''), 'x10', '')
    , imw.mrtitle
order by replace(replace(substring(sd.mrref_to_mr, charindex('l', sd.mrref_to_mr)), 'l', ''), 'x10', '') desc

The field that it's complaining about is something like:

它抱怨的领域是这样的:

L5587x6 5587 or it will have something like 5587 or L5587x6

L5587x6 5587或它有类似5587或L5587x6的东西

I need just the 5587 but I need it as a numeric value it seems. I just need to match it to another field which is mrID and it is an int

我只需要5587,但我似乎需要它作为数值。我只需要将它与另一个mrID字段匹配,它就是一个int

1 个解决方案

#1


0  

You have unmatching parenthesis in your SELECT clause. Formatted it looks like:

SELECT子句中有不匹配的括号。格式化它看起来像:

select  count(sd.mrid) ,
        replace(
            replace(
                substring(sd.mrref)to_mr, charindex('l', sd.mrref_to_mr), len(sd.mrref_to_mr)
            ), 'l', ''
        ), 'x10', '') 

I think you may have cut a function out and only removed a portion of it.

我想你可能已经删除了一个功能,只删除了一部分功能。

#1


0  

You have unmatching parenthesis in your SELECT clause. Formatted it looks like:

SELECT子句中有不匹配的括号。格式化它看起来像:

select  count(sd.mrid) ,
        replace(
            replace(
                substring(sd.mrref)to_mr, charindex('l', sd.mrref_to_mr), len(sd.mrref_to_mr)
            ), 'l', ''
        ), 'x10', '') 

I think you may have cut a function out and only removed a portion of it.

我想你可能已经删除了一个功能,只删除了一部分功能。