How to split single column into 2 columns by delimiter

pandas split one column into multiple columns
how to split one column into multiple columns in excel
how to split one cell into two in excel
split excel cell into two rows
pandas split column into multiple rows
excel split cell by delimiter formula
pandas split dataframe by column name
pandas split column by multiple delimiter

I have a table with the following schema

a   |   b   |   c
qqq | www   | ddd/ff
fff | ggg   | xx/zz
jjj | gwq   | as/we

How would I write a query so my data comes as

a   |   b   | c_1 | c_2
qqq |  www  | ddd | ff
declare @t table(a varchar(20),b varchar(20),c varchar(20))
    insert into @t values('qqq','www','ddd/ff')

SELECT  a, b, 
        left(c,charindex('/',c)-1) As c_1,
        right(c,charindex('/',reverse(c))-1) As c_2 

or, if column c does not always have the format xxx/yyy, you need to validate charindex position:

declare @t table(a varchar(20),b varchar(20),c varchar(20))
    insert into @t values('qqq','www','ddd/ff'), ('qqq','www','dddff')

SELECT  a, b, 
        case when charindex('/',c) > 0 then left(c,charindex('/',c)-1) else c end As c_1,
        case when charindex('/',c) > 0 then right(c,charindex('/',reverse(c))-1) else null end As c_2 

How to Make One Long Column into Multiple Columns in Excel, How do you split a column into a DataFrame in Python? So in this case what we want to do is to convert this single column into multiple by applying some functions. Ways to Split delimited column into multiple rows. Method 1. String Split; Method 2. XML; Method 3. JSON; Method 4. Defined Function; 5. Query Performance; 6. Conclusion; Method 1. String_Split

You can use as follows :

select LEFT(name, CHARINDEX('/', name)-1) from test_table;

where it returns the left part of the string name, before slash, and the following command returns the right part, after slash.

select RIGHT(name, CHARINDEX('/', name)-1) from test_table;

I did a whole example as you can see:

create table test_table ( name varchar(50), substr1 varchar(50), substr2 varchar(50));

insert into test_table(name) values ('sub1/sub2');

update test_table set substr1 =
(select LEFT(name, CHARINDEX('/', name)-1) from test_table);

update test_table set substr2 =
(select RIGHT(name, CHARINDEX('/', name)-1) from test_table);

select * from test_table; 

The result is :

name      | substr1 | substr2
sub1/sub2 | sub1    | sub2

How do you split data in two columns in Excel? 0. Full Screen. Select the cell or column that contains the text you want to split. Select Data > Text to Columns. In the Convert Text to Columns Wizard, select Delimited > Next. Select the Delimiters for your data. For example, Comma and Space. You can see a preview of your data in the Data preview window. Select Next.

Patindex can also be used instead of Charindex

SELECT a,b,LEFT(c,PATINDEX('%/%',c)-1), RIGHT(c,PATINDEX('%/%',REVERSE(c))-1) FROM @t

Which feature do you use to split a column of data? Split column into two columns. Full size 700 × 362 Post navigation. Power Query – Split delimited cells into rows

Learn how to take the text in one or more cells, and split it out across multiple cells by using Excel functions. In the Convert Text to Columns Wizard, select Delimited > Next. Select the Column data format or use what Excel chose for you. Earlier, I have written a blog post about how to split a single row data into multiple rows using XQuery. Today, I came across a situation where I had to split a single column data into multiple columns using delimiter. Lets me create a sample to demonstrate the solution. Sample : Solution : Given below…

Use underscore as delimiter to split the column into two columns. # Adding two new columns to the existing dataframe. # splitting is done on the basis of underscore. Column A -----| 5675-100345-9967 7788556-5555-133 50505-985-1000088 I need help to split this column by delimiter which is "-" into several columns. Really appreciate if anyone can help to solve this. Tried to use LEFT or RIGHT function with calculated column but i think it is only useful when the digit is consistent.

For example, one of the columns in your data frame is full name and use under score as our delimiter to split the column into two columns. Let’s see how to split a text column into two columns in Pandas DataFrame. Method #1 : Using Series.str.split () functions. Split Name column into two different columns. By default splitting is done on the basis of single space by str.split () function. # bydefault splitting is done on the basis of single space.

  • Will the data always be 2 parts in column c? Is the delimiter always a forward slash? What have you tried?
  • Yes, delimiter is always a forward slash and it will always be in 2 parts, no need to handle for non 2-part columns as I would want the query to fail. I tried STRING_SPLIT(c, '/') from here… but it says STRING_SPLIT is not found
  • what version of SQL Server are you using?
  • @test acc, STRING_SPLIT is only available in SQL Server 2016 and later. What version are you using?
  • @MikeBruesch SQL Server 12.0.2000.8
  • Hi, one issue with this is that the delimiter is coming on the both columns of the split, it shouldn't come on either. For example qqq|www|ddd/ff is coming as qqq|www|ddd/|/ff ideally it would come as qqq|www|ddd|ff
  • Now throws invalid length parameter passed to left / right function
  • Edited with executable code. Do you have any row with column c in a format other than xxx / yyyy?
  • Thanks works now.. I missed one column that was malformed.