Insert To Omit Duplicate Records

  • I'm in the process of writing an insert to a table which I've been having problem getting to work correctly.

    I have one table with hundreds of rows (Table A) of which I only want to insert to Table B only those that don't already exist in table B.

    Tried a not exist and various join permutations but still not getting it right.

    Any ideas?

     

    thks

     

     

     

  • Post your table structure and the query so far, so we can figure out.

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • This is the query syntax that I've been trying to manipulate.

    insert logfilehistory(file_name,size_K,full_date,char_date,char_time)

    select fname,lsize/1024,file_date,crdate,crtime

    from #logfiles

    where not exist (select fname from #logfiles)

     

  • Try this out......

    INSERT LOGFILEHISTORY (FILE_NAME,SIZE_K,FULL_DATE,CHAR_DATE,CHAR_TIME)
    SELECT FNAME,LSIZE/1024,FILE_DATE,CRDATE,CRTIME
      FROM #LOGFILES AS a
     WHERE NOT EXIST (
                        SELECT 1 
                          FROM LOGFILEHISTORY 
                         WHERE FILE_NAME = a.FNAME
                      )

    Thanks,
    Ganesh

     

     

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply