| Author |
Topic |
|
JJins
Yak Posting Veteran
81 Posts |
Posted - 2010-10-18 : 09:59:13
|
| I accidently added duplicate data into a table. All of the data has a unique primarycode that is Rateid. I am trying to select the duplicates first and then delete them out. Below is an image of the table and then the code to follow. I believe you need to assign the primary key rateid to somthing but I am not sure how to make this work. Anyone who can help it would be much appriciated.Thanks,GrahamColumns in Table Table1RateID (PK)ApplicationID (FK)ProgramID (FK)CoverageID (FK)Attemted query.......did not work. But I am trying to isolate the unique PK that share the same data for all other colums.SELECT Rateid1.RateID, Rateid2.RateID, ApplicationID, ProgramID, CoverageID, LimitCoverageID, LimitMin, LimitMax, RateCalcCoverageID, Rate, CalcType, RateType, ExcessCoverageID, ExcessLimit, MaxofExcessLimit, EffectiveDate, ExpirationDate, PCMin, PCMax, TerritoryFROM Table1Where (Rateid1.Rateid > rateid2.rateid) and Programid between 1895 and 1912 and ApplicationID = ApplicationID and ProgramID = ProgramID and CoverageID = CoverageID and LimitCoverageID = LimitCoverageID and LimitMin = LimitMin and LimitMax = LimitMax and RateCalcCoverageID = RateCalcCoverageID and Rate = Rate and CalcType = CalcType and RateType = RateType and ExcessCoverageID = ExcessCoverageID and ExcessLimit = ExcessLimit and MaxofExcessLimit = MaxofExcessLimit and EffectiveDate = EffectiveDate and ExpirationDate = ExpirationDate and PCMin = PCMin and PCMax = PCMax and Territory = Territory |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-18 : 11:50:06
|
To have a look:select * from(row_number() over(partition by ApplicationID, ProgramID, CoverageID, LimitCoverageID, LimitMin, LimitMax, RateCalcCoverageID, Rate, CalcType, RateType, ExcessCoverageID, ExcessLimit, MaxofExcessLimit, EffectiveDate, ExpirationDate, PCMin, PCMax, Territoryorder by RateID) as rownum,*from YourTable)dtTo delete the duplicates and hold the row with the min(RateID):delete from(row_number() over(partition by ApplicationID, ProgramID, CoverageID, LimitCoverageID, LimitMin, LimitMax, RateCalcCoverageID, Rate, CalcType, RateType, ExcessCoverageID, ExcessLimit, MaxofExcessLimit, EffectiveDate, ExpirationDate, PCMin, PCMax, Territoryorder by RateID) as rownum,*from YourTable)dtwhere rownum > 1 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
JJins
Yak Posting Veteran
81 Posts |
Posted - 2010-10-18 : 12:02:07
|
| THANK you SO MUCH! I have a new post coming soon that I think you will fin interesting. Thank you for your time.Best,GG |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-18 : 12:09:28
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
JJins
Yak Posting Veteran
81 Posts |
Posted - 2010-10-18 : 13:16:57
|
| I was hoping that you could insert into your query these variables......Database= Rating_2 table = RatedataI do not follow row_number and rownum. In the table RateID is the first row if that helps.Thanks again. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-18 : 13:57:21
|
quote: Originally posted by webfred To have a look:select * from(row_number() over(partition by ApplicationID, ProgramID, CoverageID, LimitCoverageID, LimitMin, LimitMax, RateCalcCoverageID, Rate, CalcType, RateType, ExcessCoverageID, ExcessLimit, MaxofExcessLimit, EffectiveDate, ExpirationDate, PCMin, PCMax, Territoryorder by RateID) as rownum,*from Rating_2..Ratedata)dtTo delete the duplicates and hold the row with the min(RateID):delete from(row_number() over(partition by ApplicationID, ProgramID, CoverageID, LimitCoverageID, LimitMin, LimitMax, RateCalcCoverageID, Rate, CalcType, RateType, ExcessCoverageID, ExcessLimit, MaxofExcessLimit, EffectiveDate, ExpirationDate, PCMin, PCMax, Territoryorder by RateID) as rownum,*from Rating_2..Ratedata)dtwhere rownum > 1 No, you're never too old to Yak'n'Roll if you're too young to die.
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
JJins
Yak Posting Veteran
81 Posts |
Posted - 2010-10-18 : 14:10:19
|
| I got this error againMsg 156, Level 15, State 1, Line 3Incorrect syntax near the keyword 'over'. |
 |
|
|
|
|
|