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

时间:2022-02-20 08:49:30

I am trying to extract a string from a column - where the position of the string may vary; but it always starts with userid= and finishes with =|

我试图从列中提取一个字符串 - 字符串的位置可能会有所不同;但它始终以userid =开头,并以= |结束

I have almost got it working, but I keep getting the error

我几乎让它工作,但我一直得到错误

Conversion failed when converting the varchar value 'userid=xxxxxxxxxxxxxxxxxxxxxxxxxxx=' to data type int

将varchar值'userid = xxxxxxxxxxxxxxxxxxxxxxxxxxx ='转换为数据类型int时转换失败

My silly question lies around where should I add the convert command?

我的愚蠢问题在于我应该在哪里添加convert命令?

My query looks like this:

我的查询如下所示:

select 
    left(substring ([Column 1],
    charindex('userid=', [Column 1]) +7, 48),
    charindex('=|', [Column 1] - 1))
from 
    [mytable]

1 个解决方案

#1


0  

try this one

试试这个

SELECT REPLACE(
LEFT(
    substring ([Column 1],
              charindex('userid=',[Column 1]) +7, 48),
              charindex('=|',[Column 1] )
)
  , '=|','')
FROM [mytable]

#1


0  

try this one

试试这个

SELECT REPLACE(
LEFT(
    substring ([Column 1],
              charindex('userid=',[Column 1]) +7, 48),
              charindex('=|',[Column 1] )
)
  , '=|','')
FROM [mytable]