SQL charindex function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 09:05 AM
Hi all,
I need to use the SQL charindex function, but I'm getting a databricks error that this doesn't exist. That can't be true, right? Thanks for any ideas about how to make this work!Barb- Labels:
-
SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 09:28 AM
Hi @Barb Krienke, Please use %sql in Databricks notebook cell.
%sql
SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2019 09:04 PM
Hi @Shyamprasad Miryala
I added %sql to the notebook cell and it did not work.
Were you able to get it to work in Databricks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 08:10 PM
%sql
--The closest thing I found was instr()
SELECT instr(Attribute, 'MatchString')
FROM TableA tba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2019 09:06 PM
Thanks for trying @jconno
Unfortunately I need to be able to specify the position where the search for the character needs to start. So just finding the first occurrence of the character is not going to help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 07:48 PM
Hi @bkrienke,
It may usefull.
%sql
SELECT position('bar', 'foobarbar', 5);
-- 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2020 10:14 PM
The best option I found to replace CHARINDEX was LOCATE, examples from the Spark documentation below
> SELECT locate('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' IN 'foobarbar');
4

