Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
silviustanimir committed Nov 14, 2023
1 parent e5b8c10 commit a9f47a4
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions macros/multiple_databases/charindex.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{%- macro charindex(expression_to_find, expression_to_search, start_location=None) -%}
{%- if start_location is none -%}
{%- if target.type == 'databricks' -%}
position('{{ expression_to_find }}', '{{ expression_to_search }}')
{%- else -%}
charindex('{{ expression_to_find }}', '{{ expression_to_search }}')
{%- endif -%}
{%- else -%}
{%- if target.type == 'databricks' -%}
position('{{ expression_to_find }}', '{{ expression_to_search }}', '{{ start_location }}')
{%- else -%}
charindex('{{ expression_to_find }}', '{{ expression_to_search }}', '{{ start_location }}')
{%- endif -%}
{%- endif -%}
case
when len('{{ expression_to_find }}') > 0
then
{% if start_location is none -%}
{% if target.type == 'databricks' -%}
position('{{ expression_to_find }}', '{{ expression_to_search }}')
{% else -%}
charindex('{{ expression_to_find }}', '{{ expression_to_search }}')
{% endif -%}
{% else -%}
{% if target.type == 'databricks' -%}
position('{{ expression_to_find }}', '{{ expression_to_search }}', '{{ start_location }}')
{% else -%}
charindex('{{ expression_to_find }}', '{{ expression_to_search }}', '{{ start_location }}')
{% endif -%}
{% endif -%}
else
0
end
{%- endmacro -%}

0 comments on commit a9f47a4

Please sign in to comment.