Can anyone help me with a SQL string ? or point me in the right direction?

I have a colum called ctn_node_path which has results like

PARTS & ACCESSORIES > PSJOHNSON - SEDDON JOHNSON PARTS > JN - JOHNSON PARTS

I am trying to split the string into three

PARTS & ACCESSORIES
SJOHNSON - SEDDON JOHNSON PARTS
JN - JOHNSON PARTS

I am using RTRIM(LEFT (ctn_node_path, CHARINDEX(' > ',ctn_node_path, 0))) to get the first part of the string
however getting Function argument count error can anyone help?

I only use MySQL, not MSSQL, but it looks like there is a STRING_SPLIT() function which lets you split a string by a specific delimeter. In this case, the delimeter would be ' > '. Hope this helps.

CHARINDEX is 1 based, not 0.

The following works for me on the developer edition of SQL Server:

SELECT RTRIM(LEFT (ctn_node_path, CHARINDEX(' > ', ctn_node_path, 1))) FROM yourTableNameHere

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.