Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find duplicate records.

Status
Not open for further replies.

Jaytib

Programmer
Sep 7, 2010
19
US
RPGer trying SQL. I've read some of SQL posts in this forum but only see snippets of code and don't understand all of it. This is what I came up with just from using my SQL book and reading posts. I want to get detail for the hdr record cust/date. Then I want to delete dups and update the date if it doesnt match the hdr. Think I need another loop for checking for dup items? I have a cursor for all detail, and then should I add another cursor to check all the detail for dup items?
This is the subprocedure I am creating with a few comments. Any help will be appreciated. Have a great one!!

// Declare Cursor For customer price header and get the
// cust # with the most recent effective date

Exec Sql Declare hFile Cursor For
Select Distinct hCNBR, Max(hDATE)
From hFile
Group By hCNBR ;
Exec Sql Open hFile ;
Dow Loop ;
Exec Sql Fetch Next From hFile
Into :hCNBR, :hDATE ;
If SqlStt = SqlNoMoreData ;
Exec Sql Close hFile ;
Leave ;
Endif ;

2nd cursor
// select detail for the most recent pricing entry to get the effective date . May contain duplicate
// items per cust, so delete the dups and update the date for all items

Exec Sql Declare dFile Scroll Cursor For
Select *
From dFile
Where dCNBR = :hCNBR and dDATE >= :hFFDATE
Order by dDATE Desc
For Read Only ;
Exec Sql Open dFile ;
Exec Sql Fetch After From dFile ;
Exec Sql Fetch Prior From dFile
Into :rdFile ; (rcdfmt, file is data structure)
If SqlStt = SqlNoMoreData;
Exec Sql Close dFile;
Leave;
Endif;

// Now I have to check if item exists in prev entries and I am not sure what to do next.
 
This doesn't look anything like TSQL, which is Microsoft SQL Server's version of SQL. Are you using Microsoft SQL Server for this project?



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I only know RPG, some Sql that I reference in SQL/400 and I develop code in RDP.
Sorry, should I ask somewhere else on this website? Thanks for looking at my post[smile]
 
I'm not 100% sure, but I think you want this forum: forum178

Please understand that I am not trying to "push you away". Instead I am trying to steer you in a better direction. One where you will more likely get better help and in a more timely fashion.

I wish you luck.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top