|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, March 09, 2011 6:07 PM
Points: 6,
Visits: 60
|
|
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[color=1001][/color] BEGIN COMMIT PRINT ' SUCCESS - no duplicate rows' END ELSE BEGIN ROLLBACK print ' Failed - duplicate rows found' END COMMIT END
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 1:25 PM
Points: 196,
Visits: 560
|
|
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, March 09, 2011 6:07 PM
Points: 6,
Visits: 60
|
|
THANKS SMITH FOR THE HELP ITS WORKING FINE FOR ME ONCE AGAIN THANK YOU
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
|
|
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 ...!!!
============================================================ SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION = http://www.sqlservercentral.com/articles/Best+Practices/61537/
|
|
|
|