You can delete your sublocations by using a stored procedure like this :
create procedure sp_DeleteSubLoc
@sublocid int
as
begin
if ((select count(*) from [posting detail] where sublocid = @sublocid) = 0)
begin
delete sublocation where sublocid = @sublocid
return 0
end
else
begin
return 1
end
end
you can use it by this way :
DECLARE @return_value int
EXEC @return_value = sp_DeleteSubLoc 15
SELECT 'Return Value' = @return_value
15 is an example for
@sublocid
, if it succeeds returns 0 otherwise returns 1.
Hope it helps.