Run the query below in SQL Server Management Studio to check for duplicate return codes:
IF exists (Select * From dbo.sysobjects Where id = object_id(N'tempDuplicateReturns') and OBJECTPROPERTY(id, N'IsTable') = 1)
Drop Table tempDuplicateReturns
Go
create table tempDuplicateReturns
(Year int, ReturnCode varchar(10), Duplicates int)
if exists (select * from ds6tc812)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TC811
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tc712)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TC711
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tc612)
Begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TC611
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tc512)
Begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TC511
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tc412)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TC411
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA312)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA311
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA212)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA211
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA112)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA111
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA012)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA011
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA912)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA911
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA812)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA811
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA712)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA711
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
if exists (select * from ds6tA612)
begin
insert into tempDuplicateReturns
SELECT year, ReturnCode, COUNT(ReturnCode)
FROM DS6TA611
GROUP BY ReturnCode, year
HAVING ( COUNT(ReturnCode) > 1 )
end
select * from tempDuplicateReturns
IF exists (Select * From dbo.sysobjects Where id = object_id(N'tempDuplicateReturns') and OBJECTPROPERTY(id, N'IsTable') = 1)
Drop Table tempDuplicateReturns
Go