I have the following code which split string in 2 pieces on the basis of space but I want to use this code to split the string in 3 pieces instead of two. is it possible ?
declare @strs nvarchar(max)
set @strs = 'Twinkle Twinkle Little Star, How I wounder what you are.'
set @strs = reverse(@strs)
select reverse(@strs) String,
reverse(right(@strs,len(@strs) - charindex(' ',@strs,30))) Description1,
ltrim(reverse(left(@strs,charindex(' ',@strs,30)))) Description2
Actually I have to copy data from table1 to table2. Table1 has field "companyname" which is varchar(120). But the table2 has 3 fields each is varchar(40)"companyname1", "companyname2","companyname3". I need to split the string in 3 pieces but in a logical way, on the basis of space and with a limit of 40 characters.
E.g if a string is "Alufinish Gesellschaft für Verfahrenstechnik u. zur Metalloberflächenbehandlung mbH & C"
it should split like this on the basis of space
"Alufinish Gesellschaft für" "Verfahrenstechnik u. zur *" "*Metalloberflächenbehandlung mbH & C"