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 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Read from CSV file

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-17 : 10:08:12
Joseph writes "i have to take data from a CSV file and save that to different tables. The CSV file is in such fotmat that its first column(header) says to which table it has to be inserted. From the second column(detailed records) it gives the values to be inserted to the table. The last column says the number of the detailed records.
before inserting to the table i have to check the number of detailed records specified in the last row are matching.

thaking you in advance
Joseph cherian"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-01-17 : 10:09:17
Can you post a sample of the CSV file, and the structure of a few of the tables it needs to insert into? It will be difficult to come up with a solution without this info.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-17 : 14:03:39
Import into a staging table using bulk insert.
Check the number of rows in the staging table against the last row.
Use the first row to create a dynamic sql statement or call an SP to insert int the relevant table (better) to insert into the production table.
You can use a function to get the columns from the correct csv entries.
see
http://www.mindsdoor.net/SQLTsql/BCP_quoted_CSV_Format_file.html
http://www.mindsdoor.net/SQLTsql/f_GetEntryDelimiitted.html


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -