Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

sql server string_split

I am using sql server 2016

I have an sql statement that gives me the rows I need with the words separated by a space.

use Dictionary

GO
SELECT [MVRIS CODE], CONCAT([Model Range], CHAR(32), [RANGE SERIES], CHAR(32), [VARIANT]) AS ConCatDesc, MARQUE
FROM ClientData.[dbo].SMMT;

Open in new window


I now need to split those words, I am trying String_Split

some of my words contain apostrophes or hyphens or + sign so all those need to remain in the word intact hence the space delimiter is perfect.

i am not sure how to merge this sql to do the split.
SELECT value 
FROM STRING_SPLIT(CONCAT([Model Range], CHAR(32), [RANGE SERIES], CHAR(32), [VARIANT],CHAR(32))

Open in new window


the concat has to remain as the 3 fields in the first select statement provide the vehicle data.

The split words will be sent to a destination table of words

the output from the first query is like this:
MVRIS CODE	ConCatDesc	MARQUE
P7AKR	IBIZA MK3 FL (Typ 6L) (SE240) REFERENCE 12V 	SEAT

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Máté Farkas
Máté Farkas
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

its saying it doesnt have enough arguments for the split
SELECT SMMT.[MVRIS CODE], SMMT.MARQUE, s.value AS [Word]
FROM ClientData.[dbo].SMMT SMMT
CROSS APPLY STRING_SPLIT(CONCAT(SMMT.[Model Range], CHAR(32), SMMT.[RANGE SERIES], CHAR(32), SMMT.[VARIANT]), CHAR(32)) s

Open in new window

I had to alter it slightly but it worked after i moved the closing argument of the concat. thank you