Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table1
--------
MainData
102-12-3445
234-42-4666

output
........

ob bc dc
102 12 3445
234 42 4666


how to split values with(-) into different columns


i am using ASP.net and SQL SERVER

so please can anyone help me with this.
Posted
Comments
George Jonsson 11-Sep-14 2:26am    
Do you want to do it in c# or with SQL in a stored procedure?
Do you want to store the data in different columns in the database or do you want to do it in a DataTable on the client side?
10923679 11-Sep-14 3:34am    
yeah i want it in c# in a store procedure

There is no ready-made Split function in SQL server.Use Substring and Charindex to perform your task.

Below are some links:
How to split a string in sql server 2008 using stored procedure and insert the data to table[^]

http://www.aspdotnet-suresh.com/2013/07/sql-server-split-function-example-in.html[^]
 
Share this answer
 
Comments
10923679 11-Sep-14 3:42am    
thank you
Hi,

check this How to Split a Column value in Sql Server[^]

Hope this will help you.

Cheers
 
Share this answer
 
Comments
10923679 11-Sep-14 3:42am    
thank you
Select
Parsename(replace(MainData,'-','.'),3) as ob,
Parsename(replace(MainData,'-','.'),2) as bc,
Parsename(replace(MainData,'-','.'),1) as dc from table1


i have got my result..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900