Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Statement – CHARINDEX Invalid Function

I want to split a string and get the value after the space and am using below query. However i am getting an error that CHARINDEX is not valid. Are there any ways i can get around this?enter image description here

SELECT  productname,
SUBSTRING(productname, instr(' ', productname) +9, 50) AS ShortProductName       
FROM   ar_cem_financedb_analytics_finance.dimproduct

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Hive does not support SQL Server’s CHARINDEX() function.

In your 2nd query you are using INSTR() but the arguments are reversed.
Change to:

SUBSTRING(productname, instr(productname, ' ') +9, 50)

or use LOCATE():

SUBSTRING(productname, locate(' ', productname) +9, 50)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading