دوست عزیز شما باید از دستور شرطی استفاده کنی توی دستور Select یا Insert
مثلا اینطوری:
If (select TBL_C.KhazaneCode From TBL_C where TBL_C.KhazameCode IN (select TBL_A.NationCode From TBL_A Where TBL_A.KhazaneCode And TBL_A.KhazaneCode=125) Is null
Select select TBL_C.KhazaneCode From TBL_C where TBL_C.KhazameCode=TBL_A.KhazaneCode And TBL_A.KhazaneCode=125
else
select TBL_A.NationCode From TBL_A Where TBL_A.KhazaneCode Not in (select TBL_C.KhazaneCode From TBL_C)
البته کد بالا یه کد ابتدایی هستش و میتونید خودتون خیلی جامعش کنید.