0

这是输入

fld_Detail
Saved dollar rate, gold volume as: 42.61, 1663.40
312000000000083: Saved as GENT'S RING, , 18K, 11.20, 0.00
312000000000083: Saved as GENT'S RING, , 18K, 11.20, 0.00
312000000000104: Saved as NECKLACE W/ CONT. PENDANT GOLD, , 14K, 8.90, 0.00
312000000000064: 350
312000000000080: 340
312000000000082: 340

如何更改或拆分这组记录以实现这种输出

fld_DetailNumbers
312000000000083
312000000000104
312000000000064
312000000000080
312000000000082

简而言之,我想根据第一条记录检索“ : ”左侧的不同数字

我不知道如何拆分整行并检索其不同的值。

4

2 回答 2

2

您可以通过一些字符串操作来做到这一点:

select left(fld_detail, charindex(':', fld_detail) - 1) as valueToLeftOfColon

如果您想将其作为数字,请将其转换:

select cast(left(fld_detail, charindex(':', fld_detail) - 1) as decimal(18, 0))

编辑:

要仅获取数字,您可以执行以下操作:

select (case when fld_detail like '%:%' and fld_detail not like '%[^0-9]%:'
             then cast(left(fld_detail, charindex(':', fld_detail) - 1) as decimal(18, 0))
        end)
. . .
where fld_detail like '%:%' and fld_detail not like '%[^0-9]%:';
于 2013-08-22T01:52:43.380 回答
2

我认为您正在寻找的是:

select substring(fld_Detail, 1, charindex(':', fld_Detail)-1 )
where isnumeric(substring(fld_detail,1,1)) = 1

它不是很有效,但是您的数据不是第 3 范式。

于 2013-08-22T01:59:30.150 回答