General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 4th, 2004, 04:40 AM
lee lee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 lee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy date arithmetics

i want to create a trigger for when software is uninstalled within 30 days, a refund is given to the owner.
i have the tables...

installation(packid, tagnum, instdate, instcost)
machine(tagnum, deptno)
pc(tagnum, empnum)
depart(deptno, balance)
employee(empnum, balance)
each machine is owned and can be found in a depart. if machine.deptno is null, then machine is assumed to reside at home and belongs to the employee. i want the trigger to update the balance of the corresponding depart or employee by the full instcost if software is uninstalled in 30 days.

i've tried the following, but it keeps compiling with errors. i don't know what i'm doing wrong, can someone please help! perhaps there's a simpler way to do this...

create or replace trigger t_refund
before delete on installation
for each row
declare v_mdeptno machine.deptno%type;
begin
select (*) into v_mdeptno
from machine
where tagnum = ld.tagnum;
if datediff('dy',sysdate,instdate) < 30
and v_mdeptno = 0 then
update employee
set balance = balance - ld.instcost
where empnum = (select empnum from pc where tagnum = ld.tagnum);
else if
datediff('dy',sysdate,instdate) < 30
and v_mdeptno >= 1 then
update depart
set balance = balance - ld.instcost
where deptno = (select deptno from machine where tagnum = ld.tagnum);
else
null;
end if;
end;


Reply With Quote
  #2  
Old April 5th, 2004, 05:35 AM
michlmann michlmann is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 56 michlmann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
With "else if" you've opened an additional if block. And for that block the "end if" is missing. Use elsif instead of else if.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > date arithmetics


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT