Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to break in individual columns

Author  Topic 

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2015-01-02 : 04:26:45
Hi
I am recieving complete row in one single column and I have pipe delimeter in this row . I want to retrieve the data in individual columns

Currently row is in one column

Data
02|vinod sahu

Expected output

Col1 col2
02 VInod Sahu


please suggest me on this

Vijay is here to learn something from you guys.

mandm
Posting Yak Master

120 Posts

Posted - 2015-01-02 : 07:49:23
If you search SQL Team for split string you will find a number of solutions.

Here is one of them.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=157949
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2015-01-05 : 03:12:39
declare @new table
(id int not null identity(1,1),
data nchar(50))
insert into @new
select'02|vinod sahu'
select*from @new
select substring(data,1,2) as col1 ,substring(data,4,10) as col2 from @new

http://sql-az.tr.gg/
Go to Top of Page

Tusharp86
Starting Member

9 Posts

Posted - 2015-01-05 : 04:08:06
select
SUBSTRING(data, 1, CHARINDEX('|', data) - 1) as Col1 ,
SUBSTRING(data, CHARINDEX('|', data) + 1, LEN(data)) as Col2
from tablename
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2015-01-05 : 04:26:46
Also refer this http://beyondrelational.com/modules/2/blogs/70/posts/10844/splitting-delimited-data-to-columns-set-based-approach.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -