after having this, I have created this function
Main Topics
Browse All TopicsGood evening Experts,
I have a table, Extract, that has some 42 fields. I have two text files. One has some of the fields in Extract and the other has the rest. Both files have some of the same fields. I was successful in creating a BULK INSERT using a Format File, however, some of the records would get transposed resulting in fewer records being imported. The text files have TAB as the deliniator.
Since the BULK INSERT didn't go well separating the fields (mainly the last field) I resorted in importing the ENTIRE row into one field in Extract. This process works every time.
My issue now is breaking up the one large row into separate fields. I was looking at SPLIT functions. I was trying to figure out how to write a function to SPLIT each row into respective fields based upon the number of TAB deliniators.
I think temporary tables should be used, but I am unsure as to the approach and subsiquent T-SQL coding.
Could you please give me some guidance. I want the function to take the SPLIT line (field data) and INSERT it to the real table, Extract. Thank you in advance for the help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
here is a sample...
select e.*,
dbo.nthItem(e.rowline, 1, ' ') Item1,
dbo.nthItem(e.rowline, 2, ' ') Item2,
dbo.nthItem(e.rowline, 3, ' ') Item3,
dbo.nthItem(e.rowline, 4, ' ') Item4,
dbo.nthItem(e.rowline, 5, ' ') Item5,
dbo.nthItem(e.rowline, 6, ' ') Item6,
dbo.nthItem(e.rowline, 7, ' ') Item7
from extract e
Hello HainKurt:,
The code you sent works great! The SPLIT function in particular. I tried it in a new query using a string I created that had a Tab character.
The code I have below is what I am trying to call the SPLIT function from. I renamed the function as you can see....
DECLARE @iRecCount integer
DECLARE @iLoop integer
SET @iLoop = 0
SELECT @iRecCount = COUNT(*) FROM [ICMTS-ACTables].[dbo].[tb
PRINT @iRecCount
WHILE @iLoop < 10
BEGIN
SET @iLoop = @iLoop + 1
SELECT e1.*, dbo.fncSplit(e1.TableLine,
WHERE @@RowCount = @iLoop - 1
END
The one record that has the TABs in it is called TabLine. It is the only field in the one table I used to import the text file to using BULK INSERT. The problem I am having now is that when I ran the code aboe with the fncSplit in it SQL Server indicates that it cannot find the function. The function is in the same database as the Extract table that I am working with. I used the iLoop so I could use the specific RowCount to work with specific rows one at a time.
Is this an OK approach or is there a better one?
The tblExtract table has one field as mentioned. This Stored Procedure will read each line from tblExtract and SPLIT the row into the respective fields into a different table called tblAssetExtract. Each row has about 42 fields. Some of the feals can be NULL.
The end result of this question will be that the SPLIT function will use the tblExtract to hold all of the BULK INSERTed text and tblAssetExtract will hold the results after each record is separated into its respective fields.
Just so you know there is another file that will be imported after the first which has a different group of fields. This is just background information for you.
Hello HainKurt,
I see. That is why the second function was created. The function works well indeed. I used it to return the 32 fields from the table. The table has some 26,000+ records in it. Is there a way to spead up this process? Right now it is taking around 10 minutes to complete.
I also think that the way these functions are set up I can use 'Item#' as the field to store in the desired table.
Business Accounts
Answer for Membership
by: HainKurtPosted on 2009-11-07 at 20:49:09ID: 25769425
hi,
ip/20009
I have some tools which you can solve your problem...
here is a modified split function of http://www.devx.com/tips/T
Select allOpen in new window