Created
May 27, 2018 12:53
-
-
Save ateneva/a396e711de4565a855f3ff48fcfe84e6 to your computer and use it in GitHub Desktop.
How do I find the first position of a string within a string with SQL?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------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 | | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment