If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > whats wrong with this?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-09, 11:57
skarri skarri is offline
Registered User
 
Join Date: Sep 2008
Posts: 16
whats wrong with this?

Here i have two tables
1> attendenace--column-->empid,indate,outdate..............
2> employees--column---> empid..........

i AM required to insert all the employee id's(frm employee table) into attendance table that are not present attendace table for given indate(date)
as other column for the newly inserted empid will be allocated with nulls i have to convert them to 0's

Now the problem is if i run this trigger after the first insert all the other employees are set to zeros so i probably have to run a time based trigger which i am not aware of can u help me:

i have come this far please make the correction for the code:

---------------------------------------------------------------------------
CODE
----------------------------------------------------------------------------
Quote:
CREATE TRIGGER test AFTER INSERT on attendance
FOR EACH ROW
BEGIN

insert into attendance(empid,indate) values(employee.empid,sysdate) where empid= (select empid from employee where empid not in(select empid from attendence where indate=sysdate)) ;

UPDATE table attendance SET field=0 WHERE field IS NULL;

end;
------------------------------------------------------------------------------------
__________________
"TALK SENSE TO FOOL. HE CALLS U FOOLISH"

Last edited by skarri; 06-24-09 at 12:02.
Reply With Quote
  #2 (permalink)  
Old 06-24-09, 17:18
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Nope, you are not required to do that.
Employees who do not exist for a given time period can easily be identified by the fact that they do not have a record in the table!
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On