SQL COMPARE HELP!!!

  • Hello,

    I need to write a few lines of SQL that will suppress one file from another. I work in foxpro 2.6 for DOS (i know its old but it works for us) we have name and address files. We want to suppress one .dbf from another .dbf. Here is what i have but it wont work. HELP!!

    Thanks!!

    &&&& A prg to supress two files based on Z5, LN , AD - FEB 2013 GH

    &&&& "FEBSUP.PRG" all standard files

    SELECT * ;

    FROM LARGE, small ;

    WHERE LARGE.Z5 <> small.z5 and Large.ln <> small.ln and Large.fn <> small fn ;

    ORDER BY LARGE.Z5 ;

    INTO TABLE SUPP.DBF

  • You might be best asking that in a dedicated FoxPro forum not a Microsoft SQL Server forum.

    Someone who knows FoxPro may stumble across the post and help, but I am not aware of many FoxPro people here.

  • gh449 (2/18/2013)


    Hello,

    I need to write a few lines of SQL that will suppress one file from another. I work in foxpro 2.6 for DOS (i know its old but it works for us) we have name and address files. We want to suppress one .dbf from another .dbf. Here is what i have but it wont work. HELP!!

    Thanks!!

    &&&& A prg to supress two files based on Z5, LN , AD - FEB 2013 GH

    &&&& "FEBSUP.PRG" all standard files

    SELECT * ;

    FROM LARGE, small ;

    WHERE LARGE.Z5 <> small.z5 and Large.ln <> small.ln and Large.fn <> small fn ;

    ORDER BY LARGE.Z5 ;

    INTO TABLE SUPP.DBF

    Try changing the ANDs to ORs in the WHERE clause.

  • I tried that getting dozens on duplicates on the output file? Thank you!!!!

  • gh449 (2/18/2013)


    I tried that getting dozens on duplicates on the output file? Thank you!!!!

    Confused. Did it help or not?

    If not, what is the problem. I am not a Foxpro developer but this does appear to be basic SQL. The only thing I see missing in the query is a join between the data in the tables.

    Not being able to see what you see makes it even harder.

  • -- Collect the matches

    SELECT l.ID ;

    FROM LARGE l ;

    INNER JOIN small s ;

    ON s.ID <> l.ID ;

    AND LARGE.Z5 = small.z5 and Large.ln = small.ln and Large.fn = small.fn ;

    INTO TABLE SuppressedRows.DBF ;

    -- Then use the ID's to restrict table LARGE

    SELECT l.ID ;

    FROM LARGE l ;

    WHERE l.ID NOT IN (SELECT ID FROM SuppressedRows) ;

    INTO TABLE SuppressedRows.DBF ;

    -- You might be able to do this in one step (it's a while since I've used Foxpro SQL)

    SELECT l.ID ;

    FROM LARGE l ;

    WHERE l.ID NOT IN ( ;

    SELECT l.ID ;

    FROM LARGE l ;

    INNER JOIN small s ;

    ON s.ID <> l.ID ;

    AND LARGE.Z5 = small.z5 and Large.ln = small.ln and Large.fn = small.fn) ;

    INTO TABLE SuppressedRows.DBF ;

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thank you very much. This is amazing!!!

Viewing 7 posts - 1 through 6 (of 6 total)

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