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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Spilt column in Sql 2008

Author  Topic 

piya
Starting Member

1 Post

Posted - 2011-07-18 : 12:57:15
Hi, I need huge help. I am struggling since so long to get the solution for my problem.

I have one text file(EDI file). I want to load it into sql table, based on certain condition. The part of the work I have done, I am able to bulk insert the text file into the temp table. Now I want to load the data from temp table to the original table with certain conditions.
Like :in the bulk inserted filed of the temp table I have separated out the filed based on raw terminator now I want
if the first three starting character are "REF" in the string then next filed after the * should go into one column of the original table and then 3rd should go to another column and so on until the raw terminator.

~BGN*00*500307680120110708C001*20110709*0404****2~
~REF*38*5003076801~
~N1*P5*INDIANA HEALTH COVERAGE PROGRAM*ZZ*IHCP~

Can anybody help me in this. I will really appreciate your help.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-18 : 17:58:38
You can try to do it with charindex to parse the data into multiple columns. However, I think that would be too hard to do if you have a lot of columns that you want to parse.

An easier way would be to use a splitter function to split each row the way you want it, and then use that to populate the table. There are several splitter functions available, for example in Fig. 21 in here So the steps would be:

1. Split the rows and put into a new temporary or virtual table.
2. Use the data from the temp table to populate your final destinations.

From your description it is hard to write code for someone who is not familiar with your database and tables. If you can post some sample data and DDLs for the tables, I am sure someone on the forum will be able to help more than offer vague suggestions like I did. Brett's blog might help
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-19 : 05:04:37
Also read this post
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/11/splitting-delimited-data-to-columns-set-based-approach.aspx

Madhivanan

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

- Advertisement -