Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Parsing text file and updating the output to database records Expand / Collapse
Author
Message
Posted Friday, June 20, 2008 2:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2008 7:30 AM
Points: 4, Visits: 12
Iam new to SQL 2005,
can anyone help me how to parse a text file (record by record every entry) and update the output to database records.

How to implement this using a Stored procedure or a Function.
Post #520430
Posted Friday, June 20, 2008 8:24 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, April 14, 2014 1:34 PM
Points: 15,442, Visits: 9,588
I'm assuming what you mean is a text file with rows and columns of data in it. Is that correct? (Some examples would be comma-delimited data, or fixed-width data.)

If so, then there are a number of options, including bcp, bulk insert, and openrowset. Take a look at ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/19049021-c048-44a2-b38d-186d9f9e4a65.htm in Books Online (search for "bulk import"). It has data on all of these methods.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #520734
Posted Monday, June 23, 2008 1:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2008 7:30 AM
Points: 4, Visits: 12
Thank you GSquared,

Sorry i could not explain the requirement properly as i has to hurrry..

Anyways, the text file is a comma-delimited file(csv) with 6 entries(columns) in each row,
With 'bulk insert' im able to push all the text data into a table.

But the requirement is not to push the entire data,
I have to extract 1,2 and 5 columns from the file and enter only those values to a SQL-DB table.(3 columns)

I have to parse the text file word by word or (character by character) and if "," is arrived at, the value needs to be pushed into DB.

I don't know how to parse the text file in SQL.
Can you please help me out as to how i can parse the csv file in SQL??
Post #521572
Posted Monday, June 23, 2008 7:46 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, April 14, 2014 1:34 PM
Points: 15,442, Visits: 9,588
Can you post some sample lines of the input data, and the desired end result of what is supposed to go into the database? If so, I can almost certainly help out.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #521777
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse