有没有人可以帮我在SQL Server中修剪下面的示例文本?我希望获得这两个'-'
之间的数据(有些行没有'-'
).
AB DCE
CM-AB DCE -228
ABC
CM-AB DCE-214
CJ-ABC-228
预期yields 为:
AB DCE
AB DCE
ABC
AB DCE
ABC
我试过:
select substring(mycol, 4, charindex('-', mycol, 12) )
但结果并不准确.
有没有人可以帮我在SQL Server中修剪下面的示例文本?我希望获得这两个'-'
之间的数据(有些行没有'-'
).
AB DCE
CM-AB DCE -228
ABC
CM-AB DCE-214
CJ-ABC-228
预期yields 为:
AB DCE
AB DCE
ABC
AB DCE
ABC
我试过:
select substring(mycol, 4, charindex('-', mycol, 12) )
但结果并不准确.
这个问题似乎已经在这里得到了回答
https://www.webcodeexpert.com/2016/08/sql-server-query-to-get-string-between.html个
SELECT SUBSTRING(txt,CHARINDEX('-',txt)+1,
(((LEN(txt))-CHARINDEX('-',REVERSE(txt)))-CHARINDEX('-',txt)))
AS Result FROM tab