I routinely get in testing files in CSV/Excel format from standardized testing services with individual students first and last names in separate columns. My sop is to go through each student listed and match them up with students in my database to assign each row in the csv/Excel the student's student number. This is a time consuming process, so I wanted to let SQL do all the heavy lifting for me.
The idea is to create a temporary table with four fields, studentID
and studentName
to be populated from the existing student table in the database and the first and last names from the CSV/Excel file. Then, I can have SQL look up the first and last name from the CSV file and populate the studentNumber
and StudentName
fields in the temporary table so I can download the table and go through the list much quicker.
I can get the temporary table created and populate the firstName
and lastName
from the CSV/Excel file, but I'm having problems pulling the data in from the excising students table.
Any help would be appreciated.
CREATE TEMPORARY TABLE processing(
studentID int(11),
studentName varchar(50),
firstName varchar(20),
lastName varchar (30)
);
INSERT INTO processing (firstName, lastName) VALUES ('John', 'Doe');
INSERT INTO processing (firstName, lastName) VALUES ('Evelyn', 'Smith');
UPDATE processing p
INNER JOIN students s
ON (s.studentName like '%p.firstName%' and s.studentName like '%p.lastName%')
SET p.studentID=s.studentID, p.studentName=s.studentName;
SELECT * FROM `processing` WHERE 1;
When the code is run, the firstName
and lastName
are there, but I get NULLs for the studentID
and the StudentName
.