[KLUG Members] Re: Database import help

Adam Tauno Williams members@kalamazoolinux.org
Thu, 27 Feb 2003 21:12:08 -0500


>Ok.. not to sound to dumb .. ( though I will profess
>my ignorance when it comes to SQL statements) 
>I understand the Joining of tables.. but I have no
>reference to the crosswalking of data you are speaking
>of.. I have about 3 different references (though most
>are on administering the database and only 1 is on
>actual query structure) So I assume you are saying
>that I could setup a Query that will Insert all the
>data from Temptable to Live table except for the field
>that needs to change? Or would I do the insert and
>then have to run an Update on those rows that I just
>inserted to do correct that field? 
>Could you point me to a good Transact-SQL reference
>that may help me in my search (I would rather learn
>than ask for an out right answer). 

for example

Database -

table mapper (link_id char(10), student_id char(10), .....
table grades (link_id char(10), class_id char(10), grade char(10), ....

Data -

student_id|class_id|grade

Do something like (syntax will vary depending upon specific DB) -

create temp table abc (student_id char(10), class_id char(10), grade char(10));

load from "/tmp/studentcrap.unl" delimiter "|"
insert into abc (student_id, class_id, grade);

insert into grades(link_id, class_id, grade)
select b.link_id, a.class_id, a.grade
from abc a, mapper b
where a.student_id = b.student_id