I have 3 tables:
CustomerID Name Sname Zipcode 1 test1 test1 xxx2 2 test2 test2 yyy2 3 test3 test3 xxx2 Table 2
StaffID Name sname 1 Jack Mack 2 Jhon Addison
ID CustomerID StaffID 1 1 1 I am not sure if SQL can do this, So in C# what I want is if StaffID 2 is not in Table 3 and if a staff wants to visit all the customers in zipcode xx2 then by click on a visit button he should be inserted for all the zipcode. So if I select Zipcode xxx2 then the query should first check if I am not visiting same Zipcode for a specific, if not then add the person into table 3 so the updated table 3 will look something like this:
ID CustomerID StaffID 1 1 1 2 1 2 3 3 2 As you can see, StaffID 2 would like to visit xxx2 zipcode as a result he gets 2 entries into Table 3 because there are two CustomerID with Zipcode same as xxx2.
I have did some online research I would this
IF EXISTS (SELECT but it just add one entry. Also I guess I will be expecting 3 parameter from C# zipcode, CustomerID and StaffID