Snowflake Vs MS-SQL - Part 55 - POSITION

                


POSITION

If you want to search for a single character or group of characters in another string.

------------------------------------+------------+
 Available_String                   | Position_1 |
------------------------------------+------------+
 nevermore1, nevermore2, nevermore3.|  1         |
 -----------------------------------+------------+

In this case, we want to search "nevermore" in the string "nevermore1, nevermore2, nevermore3.". It should return the position as 1.

MS-SQL Server

We can achieve this by using the CHARINDEX() as below.


To get the second occurrence, we need to use the third parameter of CHARINDEX() as CHARINDEX('nevermore', province,5).


In Snowflake, we can use a similar approach, which is REGEXP_INSTR()


This gives you the flexibility to find a second occurrence as well.

There is one more function POSITION().




For more details, you can refer to the following REGEXP_INSTR & POSITION.



Yogesh Shinde

LinkedInProfile

<<< Back Next >>>

Comments

Popular posts from this blog

Snowflake Vs MS-SQL - Part 36 - SPLIT_TO_TABLE

Snowflake Vs MS-SQL - Part 63 - ON Clause & Cross Join

Snowflake Vs MS-SQL - Part 33 - INITCAP