Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         mircea.stancu 
                                        Starting Member 
                                         
                                        
                                        4 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2008-08-27 : 06:22:38
                                            
  | 
                                             
                                            
                                            | Hello,I would like to do a lot of sql inserts on a table and I would like that the insert sql command to be relised only if the values are not already in the table.For example, I have a table named table with two Fields: Name and Surname:Name    SurnameJeff    SteveGeorge  Markand I have the following SQL:insert into table(Name,Surname) values('John','Henry')insert into table(Name,Surname) values('Jeff','Steve')After running those commands I want the table to look like this:Name    SurnameJeff    SteveGeorge  MarkJohn    HenryThank you!Mircea. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     georgev 
                                    Posting Yak  Master 
                                     
                                    
                                    122 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-08-28 : 05:19:00
                                          
  | 
                                         
                                        
                                          Couple of methods: make those columns unique (I believe in Access your only option is to make these two columns the composite primary key) - this will cause duplicate inserts to fail.Your other option is to check the existance of the record using a domain function (e.g. DLookup) before performing the insert command: this leads you more in to VBA land.They're the best answers I can give based on the information provided. George  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     mircea.stancu 
                                    Starting Member 
                                     
                                    
                                    4 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-08-28 : 05:37:06
                                          
  | 
                                         
                                        
                                          | Thank you so much for answering,The problem is that if I make the column unique, this will not only cause duplicate inserts to fail, but it will also stop the other good inserts from processing. My idea now is to figure out a condition in the program that transmits the sql to the database, as when it encounters an error because of duplicate inserts to move on to the next line of insert and not to stop. I'm still working on this posibility.Best regards,Mircea.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |