Parsing text file and updating the output to database records

  • 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.

  • 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

  • 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??

  • 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply