Connecting Tech Pros Worldwide Forums | Help | Site Map

Trigger and procedure

Newbie
 
Join Date: Jul 2008
Posts: 29
#1: Jul 29 '08
given a propertyid and sale amount the system should change property status to 'sold'
when it is marked sold askingprice should be added to totalsales.

property(property_id,property_name,asking_price,st atus,total_size,address,city,state,agent_id)

agent(agent_id,last_name,first_name,start_date,con tact_no,total_sales,property_id)

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Jul 29 '08

re: Trigger and procedure


Sounds like homework. What have you done so far?
Newbie
 
Join Date: Jul 2008
Posts: 29
#3: Jul 29 '08

re: Trigger and procedure


some how not getting the idea to do it

help me
Newbie
 
Join Date: Jul 2008
Posts: 29
#4: Jul 29 '08

re: Trigger and procedure


create proc sp_prop_status
(@property_id int,@asking_price float(2))
as
begin
If not exists (select * from property where property_id=@property_id)
begin
select 'not a valid property'
return
end

begin transaction
update property set status = 'sold'
where property_id=@property_id
if @@error <>0 or @@rowcount <> 1
begin
rollback transaction
select 'insert failed'
return
end
commit transaction
end

This is what i have done
Newbie
 
Join Date: Jul 2008
Posts: 29
#5: Jul 29 '08

re: Trigger and procedure


im not able to implement the 2nd part adding asking_price to total_sales when it is marked sold
Newbie
 
Join Date: Jul 2008
Posts: 29
#6: Jul 30 '08

re: Trigger and procedure


delerna or administrator plz help me out
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#7: Jul 31 '08

re: Trigger and procedure


Looks like you're expecting to update only 1 record with this condition @@rowcount <> 1, otherwise it rolls back.

-- CK
Newbie
 
Join Date: Jul 2008
Posts: 29
#8: Jul 31 '08

re: Trigger and procedure


yes ur right after updating status i should be able to use trigger to update total_sales
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#9: Aug 1 '08

re: Trigger and procedure


I mean record, not column.

If your table have many rows that will be updated @@rowcount is > 1 hence it rolls back.

If this is a homework, you have to figure out the rest.

-- CK
Reply