How do I find the first position of a string within a string with SQL?

Depending on the database you’re using, the function will be called differently and may have different syntax.

MySQL, vertica instr(full string, string to search)
PosgreSQL position(string to search in full string)
SQL Server charindex(string to search, full string, {starting position})
-------------------------------------MySQL------------------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
instr('The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy', 'impeccable') as first_pos
phrase |first_pos
-------------------------------------------------------------------------------------|----------
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30
-----------------------------------PostgreSQL---------------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
position('impeccable' in 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy') as first_pos
phrase |first_pos
-------------------------------------------------------------------------------------|----------
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30
-------------------------------------SQL server----------------------------------------------------------------
select
'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy' as phrase,
charindex('impeccable', 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy') as first_pos,
charindex('impeccable', 'The first agreement is to be impeccable with your word.
When you are impeccable, you take responsibility for your actions, but you do not judge or blame yourself!
Being impeccable with your word is not using the word against yourself.
Being impeccable with your word is the correct use of your energy',32) as second_pos
phrase |first_pos |second_pos |
-------------------------------------------------------------------------------------|----------|-----------|
The first agreement is to be impeccable with your word. ¶When you are impeccable, you|30 |71 |

As you might have noticed, the function in SQL Server has an additional argument, allowing you to search starting from any point within the full string.

The most valuable usage of these functions, however, is not in finding the exact starting position of the string per se, but rather in checking if a string exists within another…

If the function results in 0, that will indicate that the full string does not contain the one being searched

Wanna see a real-life example?