Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parsing text file and updating the output to database records


Parsing text file and updating the output to database records

Author
Message
jataa
jataa
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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.
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14385 Visits: 9729
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
jataa
jataa
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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??
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14385 Visits: 9729
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search