Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


dupliate records


dupliate records

Author
Message
chereku
chereku
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
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
Daryl AZ
Daryl AZ
SSC Veteran
SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)SSC Veteran (204 reputation)

Group: General Forum Members
Points: 204 Visits: 683
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
chereku
chereku
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 60
THANKS SMITH FOR THE HELP
ITS WORKING FINE FOR ME
ONCE AGAIN THANK YOU
Dugi
Dugi
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1316 Visits: 3511
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/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search