My requirement is to insert data into emptable and fields - empid,empfname,emplname,empfilestatus,createdate. Based on the below criteria I need to insert data into emptable. For this purpose, am using empfilestatustable & empsrctable. Here is ...I need to use curosors and loop in stored procedure to do this activity...I need help please...I have built multiple sql select statements with union to insert but it has been told to built using cursors & loop...
insert into emptable
criteria - if empid not exist in emptable then insert and set empfilestatus=2
if empid exist in emptable then do not insert and update records (in case of change in fname or lname, shouldnt update empfilestatus)
if empfilestatus is (5,6,7) then it should insert any record in emptable even though empid existing in emptable.
if empfilestatus is (4) then it should not insert any record in emptable with same empid in emptable.
if record createdate>40 days then it should insert empid in emptable even though it exists.
empfilestatustable
empfilestatus | empfilestatusname |
1 | pending |
2 | received |
3 | inprogress |
4 | cancel |
5 | complete |
6 | abonded |
7 | superseded |
empsrc table
empid | empfname | emplname | deptno |
1 | john | kerry | comp |
2 | andew | flint | purch |
3 | dinesh | pan | purch |
4 | raj | jar | purch |
5 | kary | volse | purch |
6 | danny | dize | comp |
7 | sachin | geet | edu |
8 | sonia | dsouza | edu |
9 | rajesh | kawa | comp |