Splitting the full name and writing it to another table in SQL Server 2008 -



Splitting the full name and writing it to another table in SQL Server 2008 -

i have table, a, in there column fullname. values stored under column in format of "surname name middle_name" (with 1 space between each). , have table b, in have columns surname, name , middlename. best way take of fullname cells table a, split them accordingly , insert them table b?

thanks

you can combine functions searching occurence in string (which homecoming index) substring function, besides need left , right functions

for illustration in sql server find functions:

charindex ( expressiontofind ,expressiontosearch [ , start_location ] )

substring ( look ,start , length )

left ( character_expression , integer_expression )

right ( character_expression , integer_expression )

steps:

use left 1st word (integer_expression = index of 1st emtpy space) use substring middle word (start index of 1st emtpy space + 1 , length entire length - sec index of emtpy space, utilize startlocation search sec occurence should first occurence +1) use right function lastly word similar step 1

notice if have names including empty spaces in middle (example first name anna maria) wouldnt work expected.

sql sql-server database split

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -