ورود

View Full Version : کوئری حذف از یک جدول با توجه به استفاده شدن آن در 5 ستون یک جدول دیگر



jafarpalideh
سه شنبه 11 دی 1397, 11:00 صبح
با سلام به همه
یه جدول کاغذ دارم که میام و کاغذهام رو توش تعریف میکنم.
یه جدول قرارداد دارم که 5 تا ستونش از همین فیلد آی دی کاغذ پر میشه(ریلیشن ندادم و به صورت هارد کد ذخیره کردم)
حالا موقعی که میخوام کاغذ رو از جدول کاغذ حذف کنم باس بره توی هر 5 تا ستون کاغذ در جدول قرارداد بگرده و اگه نبود اجازه ی حذف بده .
تا یه جاهاییش رفتم ولی دیگه گیر کردم .


select distinct tc.Paper_Id1 from TblContract tc


select distinct tc.Paper_Id2 from TblContract tc


select distinct tc.Paper_Id3 from TblContract tc


select distinct tc.Paper_Id4 from TblContract tc


select distinct tc.Paper_Id5 from TblContract tc






delete from TblPaper where PaperId = '1004' and PaperId.......

hamid_hr
چهارشنبه 12 دی 1397, 17:13 عصر
اینو تست کنید

delete from TblPaper where PaperId = '1004' andnot exists(select distinct tc.Paper_Id1 from TblContract tc where tc.Paper_Id1 = 4001
union all
select distinct tc.Paper_Id2 from TblContract tc where tc.Paper_Id1 = 4001
union all
select distinct tc.Paper_Id3 from TblContract tc where tc.Paper_Id1 = 4001
union all
select distinct tc.Paper_Id4 from TblContract tc where tc.Paper_Id1 = 4001
union all
select distinct tc.Paper_Id5 from TblContract tc where tc.Paper_Id1 = 4001)