Variable length substring between two characters

Greg

Data looks like this:

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.

This:

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

And this:

SELECT DISTINCT RIGHT(OPTIONAL_FIELD_2, LEN(OPTIONAL_FIELD_2)-12) AS OPTIONAL_FIELD_2
FROM my_table
ORDER BY OPTIONAL_FIELD_2

Gives me this:

Credible Sources;
Just in Time;
Database Normalization;

Having a hard time figuring out how to combine the two.

Gordon Linoff

How about just using 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, ''), ';', '')

Here is a db<>fiddle.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Getting everything between two characters

分類Dev

Search A SubString Between Two Points Of A String Dynamically

分類Dev

Extract a substring in a column which is delimited by two specific characters in Pandas

分類Dev

Find variable substring after known characters inside a string

分類Dev

Print an array between two given characters

分類Dev

If between two different characters in a text file, Python

分類Dev

How to extract a string between two characters?

分類Dev

How to remove all whitespace between a two characters?

分類Dev

Regex: Match all characters between two strings

分類Dev

Extract character between the first two characters

分類Dev

Store text between two characters in a array

分類Dev

Capture words between two special characters

分類Dev

Conflict between variable substitution and CJK characters in BASH

分類Dev

Conflict between variable substitution and CJK characters in BASH

分類Dev

Is there any method for C language to control length of characters by using a variable?

分類Dev

How can I find the nth substring in between two substrings in C?

分類Dev

Optimizing finding matching substring between the two lists by regex in Python

分類Dev

php substring occurances between two strings in an html file

分類Dev

php substring occurances between two strings in an html file

分類Dev

Remove spaces between characters in cell, but only if the space exists between two single characters

分類Dev

AngularJS - share variable between two controllers

分類Dev

Difference between two timestamp variable in php

分類Dev

Matching string between two markers that are filepaths and contain special characters

分類Dev

Get length of Substring from string

分類Dev

Optimizing MySQL table for variety of VarChar length between 20 and 4,000 characters

分類Dev

Generating all the substring of a given length using yield

分類Dev

Matlab: find the length of longest substring in sequence

分類Dev

Text between substring and first dot

分類Dev

Divide strings by length of two

Related 関連記事

  1. 1

    Getting everything between two characters

  2. 2

    Search A SubString Between Two Points Of A String Dynamically

  3. 3

    Extract a substring in a column which is delimited by two specific characters in Pandas

  4. 4

    Find variable substring after known characters inside a string

  5. 5

    Print an array between two given characters

  6. 6

    If between two different characters in a text file, Python

  7. 7

    How to extract a string between two characters?

  8. 8

    How to remove all whitespace between a two characters?

  9. 9

    Regex: Match all characters between two strings

  10. 10

    Extract character between the first two characters

  11. 11

    Store text between two characters in a array

  12. 12

    Capture words between two special characters

  13. 13

    Conflict between variable substitution and CJK characters in BASH

  14. 14

    Conflict between variable substitution and CJK characters in BASH

  15. 15

    Is there any method for C language to control length of characters by using a variable?

  16. 16

    How can I find the nth substring in between two substrings in C?

  17. 17

    Optimizing finding matching substring between the two lists by regex in Python

  18. 18

    php substring occurances between two strings in an html file

  19. 19

    php substring occurances between two strings in an html file

  20. 20

    Remove spaces between characters in cell, but only if the space exists between two single characters

  21. 21

    AngularJS - share variable between two controllers

  22. 22

    Difference between two timestamp variable in php

  23. 23

    Matching string between two markers that are filepaths and contain special characters

  24. 24

    Get length of Substring from string

  25. 25

    Optimizing MySQL table for variety of VarChar length between 20 and 4,000 characters

  26. 26

    Generating all the substring of a given length using yield

  27. 27

    Matlab: find the length of longest substring in sequence

  28. 28

    Text between substring and first dot

  29. 29

    Divide strings by length of two

ホットタグ

アーカイブ