0
INSERT INTO tblprofile (fldDate,fldemployeeno,fldLName,fldFName,fldMI,fldEmployeeName,
                        fldShiftCode,fldProjectGroup,fldTask,fldSuperior,fldPosition)
SELECT now(),tblprofile.fldemployeeno,tblprofile.fldlname,tblprofile.fldfname,tblprofile.fldmi,tblprofile.fldemployeename,
       tblprofile.fldshiftcode,tblprofile.fldprojectgroup,tblprofile.fldtask,tblprofile.fldsuperior,tblprofile.fldposition
  FROM tblprofile
 WHERE tblprofile.flddate = (SELECT MAX(flddate) FROM tblprofile p
                              WHERE p.fldemployeeno IN ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005'))
   AND tblprofile.fldemployeeno IN
       ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005');

I want to copy all current profile of all employees in a list ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005') and it seems that in my query it only insert one (1) rows..

In short, I want to try to copy all current profile of the employee from tblprofile in just one execution? Can anyone help me to do that so..

4
  • The flddate comparison - it's matching on the highest value associated to those employees, but only one of them has that value... Commented Aug 6, 2010 at 4:56
  • 1
    tblprofile.flddate = (SELECT MAX(flddate) ... it may be returning only one date among five of them... Commented Aug 6, 2010 at 4:57
  • it must do the job, are you sure that select return more than one row? Commented Aug 6, 2010 at 4:58
  • I want to get the current profiles of the employee with the help of maximum date thats why i have used MAX(flddate).. No, flddate is not nullable Commented Aug 6, 2010 at 5:08

1 Answer 1

1

From your comments it appears that a user could have multiple profiles and you want the latest and set a current date for the new profile.

Change your WHERE clause to this

FROM tblprofile t1 WHERE t1.flddate = (SELECT MAX(flddate) FROM tblprofile p WHERE p.fldemployeeno = t1.fldemployeeno) AND t1.fldemployeeno IN ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.