I have a problem splitting single column values to multiple column values.
For Example:
Name ------------ abcd efgh ijk lmn opq asd j. asdjja asb (asdfas) asd asd
and I need the output something like this:
first_name last_name ---------------------------------- abcd efgh ijk opq asd asdjja asb asd asd null
The middle name can be omitted (no need for a middle name) The columns are already created and need to insert the data from that single Name
column.
In the table, click the cell that you want to split. Click the Layout tab. In the Merge group, click Split Cells. In the Split Cells dialog, select the number of columns and rows that you want and then click OK.
Select the cell, range, or entire column that contains the text values that you want to split. On the Data tab, in the Data Tools group, click Text to Columns. Follow the instructions in the Convert Text to Columns Wizard to specify how you want to divide the text into separate columns.
Your approach won't deal with lot of names correctly but...
SELECT CASE WHEN name LIKE '% %' THEN LEFT(name, Charindex(' ', name) - 1) ELSE name END, CASE WHEN name LIKE '% %' THEN RIGHT(name, Charindex(' ', Reverse(name)) - 1) END FROM YourTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With