Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have two table OPDPatient And Registration these two table tables are linked via REGNO.
Now I want to update records of both table. For this I first deleted all the record of that particular REGNO which lies in both tables.Now i want if record of first table is deleted successfully then only second table will go for delete and then update operation occur like this:

ALTER proc Sp_Update_OPD_Registration
(
@PID varchar(30),
@Department int,
@Doctor varchar(20),
@ReffBy varchar(50),
@Diagnosis nvarchar(150),
@Category int ,
@MLC char(3),
@PoliceStation varchar(100),
@FIRno varchar(100),
@Identification varchar(100),
@Injury varchar(100),
@Signature varchar(100),
@MLC_Charge varchar(150),
@Willing varchar(50),
@Remark varchar(500),
@broughtby varchar(50),
@contactno varchar(50),
@DoctorFee money,
@AddFee money,
@Reason varchar(100),
@Discount money
)
as
Declare @result tinyint

if(@PID <>'' or @PID<> null)
BEGIN
Delete from OpdPatient where RegNo=@PID--if it is successfull
Delete from Registration where RegNo=@PID--then this delete occur
-- then this update operation
update OpdPatient set
Department=@Department,Doctor=@Doctor,ReffBy=@ReffBy,Diagnosis=@Diagnosis,Category=@Category,MLC=@MLC,PoliceStation=@PoliceStation,FIRno=@FIRno,Identification=@Identification,Injury=@Injury,Signature=@Signature,MLC_Charge=@MLC_Charge,Willing=@Willing,Remark=@Remark,broughtby=@broughtby,contactno=@contactno,DoctorFee=@DoctorFee,AddFee=@AddFee,Reason=@Reason,Discount=@Discount where RegNo=@PID
END
Posted

1 solution

visit link...
see example of using Transaction-Rollback
http://stackoverflow.com/questions/3935900/how-to-commit-and-rollback-transaction-in-sql-server[^]
Happy Coding!
:)
 
Share this answer
 
Comments
Member 8233601 20-May-13 7:43am    
actually i want to do something like this
Declare @result tinyint
@result=delete from OPDPatient where REGNO=@PID
if(@result>0)
@result=delete from OPDPatient where REGNO=@PID

please help me by providing this type of solution

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