Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
friends at present i am doing data migration from my old database to new DB.in my new Db I wrote User defined function for a table column.So the problem occur here
thank you....

SQL
CREATE OR REPLACE FUNCTION empdatamigration1()
RETURNS void AS
$BODY$
DECLARE
EMPYID CHARACTER VARYING(20);
EMPD CHARACTER VARYING(20);

begin
FOR EMPYID IN select udf_generateemployeeid(2, ('now'::text)::date) LOOP

select coalesce(max(cast(cast(empid as integer)+1 as text)),null,EMPYID) into EMPD from tblemployeemst where createddate = 'now'::date;

INSERT INTO tblemployeemst(givenname, surname, basicsal, hiredate, rgid, qualification,
otherqualif, experience, active, age, gender, dob, resphone, offphone, mobileno,emailid, mstatus, designationid, brid,empid)
SELECT distinct e.name, e.surname, e.basicsal,e.hiredate,2, e.qualification, e.otherqualif, e.experience, cast(e.actflag as boolean),ei.age,ei.gender,ei.dob, ei.resphone,
ei.offphone, ei.mobileno,ei.emailid, ei.mstatus,d.designationid,2,EMPD
FROM tabemployeemst e left outer Join tabemployeedtl ei on ei.eid=e.eid left outer join tbldesignationmst d on upper(d.designationname)=upper(e.designame);

END LOOP;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION empdatamigration1() OWNER TO postgres;
Posted
Updated 22-Aug-15 13:25pm
v2
Comments
Andy Lanng 21-Aug-15 4:19am    
post the code
User-11630313 21-Aug-15 4:26am    
Removed code from comment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900