Hi,
I want to have my sp to delete child records.
The problem is the child record could be over 1.
I'm not allowed to create a table to put the child
records and delete them. Any idea to resolve this problem?
Thank you .....
--Here is the sp
declare @count int,
@inv_id int,
@child_inv_id int
set @inv_id = 1234
select @count = count(*) from table1 where parent_inv_id = @inv_id
if @count =0
begin
delete table1
where inv_id = @inv_id
end
else
begin
select @child_inv_id = inv_id
from table1
where parent_inv_id = @inv_id
--delete the child record
delete table1
where inv_id = @child_inv_id
--delete the parent record
delete table1
where inv_id = @inv_id
end
I want to have my sp to delete child records.
The problem is the child record could be over 1.
I'm not allowed to create a table to put the child
records and delete them. Any idea to resolve this problem?
Thank you .....
--Here is the sp
declare @count int,
@inv_id int,
@child_inv_id int
set @inv_id = 1234
select @count = count(*) from table1 where parent_inv_id = @inv_id
if @count =0
begin
delete table1
where inv_id = @inv_id
end
else
begin
select @child_inv_id = inv_id
from table1
where parent_inv_id = @inv_id
--delete the child record
delete table1
where inv_id = @child_inv_id
--delete the parent record
delete table1
where inv_id = @inv_id
end