Question : Split varchar MS SQL

I need to split a string on a space,  then re assemble the results and save them to a new colonm.

i first need to check if the value contians a space, so will need to remove any leading or trailing spaces from the value. if it contains a space i will need know how many.

then split the value on the space and re assemble.

example. the value contains '123h4'  ( this is fine nothing needs doing)

the value contains 'bold 9700' i need to split this on the space and reassemble reversed, '9700 Bold' and save to a new column.

I can not figure out how to do a split and retrieve both values, what i have only allows me to retrive one value.

You help will be much appreciated

Answer : Split varchar MS SQL

you mean:
1:
2:
3:
4:
5:
6:
7:
UPDATE yourtable
  SET UPC = 
  , CASE WHEN product_modelnumber LIKE '% %' 
  THEN SUBSTRING(product_modelnumber, CHARINDEX(' ', product_modelnumber) + 1, LEN(product_modelnumber) ) + ' ' + SUBSTRING(product_modelnumber, 1,  CHARINDEX(' ', product_modelnumber) - 1)
  ELSE product_modelnumber END 

where product_ean <> 1 or product_ean is null
Random Solutions  
 
programming4us programming4us