Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

dupliate records Expand / Collapse
Author
Message
Posted Wednesday, October 1, 2008 11:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 9, 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
Post #579287
Posted Wednesday, October 1, 2008 5:13 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, September 29, 2014 3:01 PM
Points: 199, Visits: 600
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
Post #579431
Posted Thursday, October 2, 2008 11:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 9, 2011 6:07 PM
Points: 6, Visits: 60
THANKS SMITH FOR THE HELP
ITS WORKING FINE FOR ME
ONCE AGAIN THANK YOU
Post #579821
Posted Thursday, October 2, 2008 12:46 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 22, 2014 2:32 AM
Points: 1,260, Visits: 3,423
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/
Post #579899
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse