dupliate records

  • hi

    iam having this problem with duplicate records,

    I want a query which will check the table for any duplicate records if there are any duplicates it should print "table has duplicates and quit the query and if there ae no duplicates it should print "no duplicates" and executethe query, i tried to use the below query but iam getting some errors could some one help

    SELECT count(*) ,material_code

    FROM MATERIAL_UPDATES

    GROUP BY material_code

    HAVING count(*) > 1

    IF count(*) > 1

    BEGIN

    BEGIN

    COMMIT

    PRINT ' SUCCESS - no duplicate rows'

    END

    ELSE

    BEGIN

    ROLLBACK

    print ' Failed - duplicate rows found'

    END

    COMMIT

    END

  • if exists(SELECT material_code

    FROM MATERIAL_UPDATES

    GROUP BY material_code

    HAVING count(*) > 1)

    BEGIN

    select "Table has Duplicates"

    RETURN

    END

    else

    select "No Duplicates"

    -- your query here

  • THANKS SMITH FOR THE HELP

    ITS WORKING FINE FOR ME

    ONCE AGAIN THANK YOU

  • Daryl Smith (10/1/2008)


    if exists(SELECT material_code

    FROM MATERIAL_UPDATES

    GROUP BY material_code

    HAVING count(*) > 1)

    BEGIN

    select "Table has Duplicates"

    RETURN

    END

    else

    select "No Duplicates"

    -- your query here

    little nice stuff here ...!!! :hehe:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

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

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