October 1, 2008 at 11:57 am
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
October 1, 2008 at 5:13 pm
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
October 2, 2008 at 11:05 am
THANKS SMITH FOR THE HELP
ITS WORKING FINE FOR ME
ONCE AGAIN THANK YOU
October 2, 2008 at 12:46 pm
Daryl Smith (10/1/2008)
if exists(SELECT material_codeFROM 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:
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply