**Table:**
| String | Substring|
| -------- | ---------|
| Tattinger | TT |
| TT's | TT |
| TT Tattinger | TT |
| Tattinger TTa | TT |
| TTinger tab | TT |
Criterias:
- Substring can not be in the middle of string.
- Substr should always be at the start of each letters
- If there is any non-characters('.,#) after substring, that's okay.
- All other cases No
Result
| String | Substring| Result|
| -------- | --- |-------|
| Tattinger | TT |No |
| TT's tattinger| TT |Yes |
| TT Tattinger | TT |Yes |
| Tattinger TTa | TT |Yes |
| TTinger tab | TT |Yes |
What I've explored so far:
1. STRING LIKE '%' || SUBSTRING || '%'----(not suitable because it matches anywhere)
2. REGEXP_SUBSTR(STRING, SUBSTRING || '\\W') --(suitable partially)
CodePudding user response:
How about a simple case statement? I am using like
but if case isn't important change that to ilike
case when str like 'TT%' or str like '% TT%' then 'Yes' else 'No' end as flag