数据如下所示:
Initiative: Credible Sources;
Initiative: Just in Time;
Initiative: Database Normalization;
我希望它看起来像这样:
I want it to look like this:
Credible Sources
Just in Time
Database Normalization
摆脱其中一个非常简单.
It's pretty simple to get rid of one or the other.
这个:
SELECT DISTINCT LEFT(OPTIONAL_FIELD_2, CHARINDEX(';', OPTIONAL_FIELD_2 + ';')-1) AS OPTIONAL_FIELD_2
FROM my_table
ORDER BY OPTIONAL_FIELD_2
给我这个:倡议:可靠来源倡议:及时倡议:数据库规范化
Gives me this: Initiative: Credible Sources Initiative: Just in Time Initiative: Database Normalization
还有这个:
SELECT DISTINCT RIGHT(OPTIONAL_FIELD_2, LEN(OPTIONAL_FIELD_2)-12) AS OPTIONAL_FIELD_2
FROM my_table
ORDER BY OPTIONAL_FIELD_2
给我这个:
Credible Sources;
Just in Time;
Database Normalization;
很难弄清楚如何将两者结合起来.
Having a hard time figuring out how to combine the two.
仅使用 substring() 怎么样?
select replace(substring(option_field_2, 13, 999), ';', '')
或者,如果您不知道前缀有多长:
Or, if you don't know how long the prefix is:
select replace(stuff(option_field_2, 1, charindex(':', option_field_2) + 1, ''), ';', '')
这里是db<>fiddle.
Here is a db<>fiddle.
这篇关于两个字符之间的变长子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合