المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Insert values into a table only if they do not already exist in that table (MS Access)



C# Programming
09-24-2009, 08:02 PM
hi all

i have a query written in MS access which check if variables exist in the table then dont inser but if not the variables are inserted twice this is my problem.below is the code


INSERT INTO IPAdress ( IP, Machine_Name)
SELECT '3', 'sss' from IPAdress WHERE NOT EXISTS
(SELECT null FROM IPAdress WHERE IP = '3' AND Machine_Name = 'sss' )

in oracle there is a dual table so the query can be modified a bit and it works fine.the query which works in oracle is

INSERT INTO IPAdress ( IP, Machine_Name)
SELECT '3', 'sss' from dual WHERE NOT EXISTS
(SELECT null FROM IPAdress WHERE IP = '3' AND Machine_Name = 'sss' )