I am new at SQL, including performing queries. Everyday, our organization sends a list of employees that were terminated in a listed format. What I am looking to do is two things, search for the employee ID(s) in a column
and if the employee is found, update a certain cell/field to disable
.
For instance, if we get a list that has an employee ID's of 123456
and 234567
, I want to find those employee ID's in the EMPID
field and then update their ACTIVE field from '1' to '0'.
What is the best possible way to do this?
EDIT, sorry for all the missing information as I am completely new to the forum and the coding world, and I'm, going to re-explain what I am trying to accomplish. Maybe a function? I changed the data below to be more consistent with what I am working with versus examples.
We get a text file everyday with a list of employee ID's that were terminated, that we need to deactivate in our application. I know this is still manual, but I think it is a good start for some automation.
On the
dbo.EnterpriseUser
table, we need the code to find the user by looking for theIVRID
(Which is the employee's ID) and then update theIsActive
field from1
to0
, and then update theLastModDate
to the current date and time using the same format. Below is the example table I am working with, sorry if the formatting is not correct.CREATE TABLE IF NOT EXISTS EnterpriseUser ( `EnterpriseUserID` INT, `FirstName` VARCHAR(6) CHARACTER SET utf8, `LastName` VARCHAR(7) CHARACTER SET utf8, `IVRID` INT, `IsActive` INT, `LastModDate` DATETIME
); INSERT INTO EnterpriseUser VALUES (6,'Robert','Andrews',2,1,'2018-07-11 13:01:54.670000');
The second table
dbo.Staff
must be properly updated as well for the application. My only problem is that to find the record to update, I have to use theEnterpriseUserID
field fromdbo.EnterpriseUser
is now in theStaffID
field on thedbo.Staff
table.
On that row, the LastModDate
must be changed to current date and the IsActive
must change from 1
to 0
.
CREATE TABLE IF NOT EXISTS Staff (
`StaffID` INT,
`FirstName` VARCHAR(6) CHARACTER SET utf8,
`LastName` VARCHAR(7) CHARACTER SET utf8,
`LastModDate` DATETIME,
`IsActive` INT
);
INSERT INTO Staff VALUES
(6,'Robert','Andrews','2018-07-11 13:01:54.670000',1);