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.
| Author |
Topic |
|
tubes26
Starting Member
1 Post |
Posted - 2009-08-18 : 15:03:38
|
| Ok, I am a newbie to SQL so bear with me. I am trying to import data from a CSV we exported out of another program. I am creating a table and adding the data from the csv to this new table using the BULK INSERT command. The problem is that we need to add one column from this csv to an existing column in a table existing in our SQL database. The other column in this csv does not match any of the columns in the table I want to import into but does match data/columns in other tables. In fact it matches many of the primary keys. I need to import bus numbers for students from "newTable" into "transportation" table. "newTable" contains two fields, studentID and lateBus. "transportation" table containes only lateBus but not studentID. "transportation" table does contain customID which resides in a table in the database called "person" which does contain both studentID (which is in my CSV) and customID which is in the transportation table. I need the bus numbers to match according to their studentID in turn to their customID in the transportation table. Do I have to make a join in the script as well. If so, any sample syntax would be greatly appreciated. Thanks. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-08-18 : 15:21:20
|
| Load your csv file into a (new) "staging" table. The staging table will match the "structure" of your csv. It should have no constraints and the columns should be typed so that no conversion errors occur. Once you have that sql staging table loaded you can write a script to transform that data into your permanent table structures. The script can deal with all your business rules, referential integrity, etc.Be One with the OptimizerTG |
 |
|
|
|
|
|