| Author |
Topic |
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-07 : 20:30:43
|
| Hello everyone,I have a little dilemma. I have a table ALLTABLE that has duplicate records and I want to delete them. ALLTABLE has these columns with these values for example: Policy Premium Class State Entity NumberADC-WC-0010005-0 25476 63 31 1ADC-WC-0010005-0 25476 63 31 2ADC-WC-0010005-0 25476 63 31 3ADC-WC-0010005-0 1457 63 29 4ADC-WC-0010092-1 2322 63 37 1ADC-WC-0010344-0 515 63 01 1ADC-WC-0010344-0 515 63 01 2As you can see there is some duplicates in the first 3 rows and the final 2 (the entity number is the only difference). I want the table to look like this:Policy Premium Class State Entity NumberADC-WC-0010005-0 25476 63 31 1ADC-WC-0010005-0 1457 63 29 4ADC-WC-0010092-1 2322 63 37 1ADC-WC-0010344-0 515 63 01 1Thank you so much for the help. It is really appreciated. |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-05-07 : 21:13:16
|
quick and dirty:select distinct * into #temp from alltabletruncate table alltableinsert alltable select * from #temp elsasoft.org |
 |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-05-07 : 21:19:54
|
| >> select distinct * into #temp from alltableThat will give you all rows. Try something like:DELETE t1 FROM ( SELECT ROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY Col2 DESC) AS RecID FROM Table1 ) AS t1 WHERE RecID > 1 |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-05-07 : 22:42:35
|
ah, missed that last column. I had thought the entire row was duped. elsasoft.org |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-08 : 13:10:49
|
| Thank you jezemine and rmiao for your helpful responses. You saved the day!!! |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-08 : 17:07:24
|
| Hey sorry to bug you guys again. With the same dilemma but now I want to make the duplicates where the Premium column is 0. I tried to format the example a little better lol. This is the original: Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2The first 4 rows are the same policy but with 2 different states. So out of the first 4 rows, 3 are the same so there should be 2 rows set to 0. The bottom 2 rows are the same so 1 of the premiums should be set to 0. I want the table to look like this:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Thank you again for the help. It is really appreciated. |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-08 : 20:03:04
|
| I forgot to mention that a policy can also have the same entity number so for example:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2but I still need to only have 1 premium value for each individual policy and state for examplePolicy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Please anyone help!!! LOL Thank you so much! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-09 : 05:04:47
|
quote: Originally posted by madscientist I forgot to mention that a policy can also have the same entity number so for example:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2but I still need to only have 1 premium value for each individual policy and state for examplePolicy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Please anyone help!!! LOL Thank you so much!
Where do you want to show the data?If you use reports, make use of suppress if duplicated featureMadhivananFailing to plan is Planning to fail |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-09 : 12:12:01
|
quote: Originally posted by madhivanan
quote: Originally posted by madscientist I forgot to mention that a policy can also have the same entity number so for example:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2but I still need to only have 1 premium value for each individual policy and state for examplePolicy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Please anyone help!!! LOL Thank you so much!
Where do you want to show the data?If you use reports, make use of suppress if duplicated featureMadhivananFailing to plan is Planning to fail
Hi Madhivanan. I don't need to show this data anywhere. It is just in a table. I export it to a text file afterwards. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-09 : 12:17:52
|
quote: Originally posted by madscientist Hey sorry to bug you guys again. With the same dilemma but now I want to make the duplicates where the Premium column is 0. I tried to format the example a little better lol. This is the original: Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2The first 4 rows are the same policy but with 2 different states. So out of the first 4 rows, 3 are the same so there should be 2 rows set to 0. The bottom 2 rows are the same so 1 of the premiums should be set to 0. I want the table to look like this:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Thank you again for the help. It is really appreciated.
Try this:-UPDATE tSET t.Premium=0FROM(SELECT ROW_NUMBER() OVER (PARTITION BY Policy,Premium ORDER BY EntityNumber) AS RowNo,*FROM YourTable)tWHERE t.RowNo <>1 |
 |
|
|
madscientist
Starting Member
30 Posts |
Posted - 2008-05-09 : 12:28:07
|
quote: Originally posted by visakh16
quote: Originally posted by madscientist Hey sorry to bug you guys again. With the same dilemma but now I want to make the duplicates where the Premium column is 0. I tried to format the example a little better lol. This is the original: Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2The first 4 rows are the same policy but with 2 different states. So out of the first 4 rows, 3 are the same so there should be 2 rows set to 0. The bottom 2 rows are the same so 1 of the premiums should be set to 0. I want the table to look like this:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Thank you again for the help. It is really appreciated.
Try this:-UPDATE tSET t.Premium=0FROM(SELECT ROW_NUMBER() OVER (PARTITION BY Policy,Premium ORDER BY EntityNumber) AS RowNo,*FROM YourTable)tWHERE t.RowNo <>1
It seems to have worked! Thank you visakh16 for all of your help. You have come through for me in the past and I really appreciate it. Thank you as well to the others for all the help. This forum is awesome!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-09 : 12:31:25
|
quote: Originally posted by madscientist
quote: Originally posted by visakh16
quote: Originally posted by madscientist Hey sorry to bug you guys again. With the same dilemma but now I want to make the duplicates where the Premium column is 0. I tried to format the example a little better lol. This is the original: Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.....25476......63......31...............2ADC-WC-0010005-0.....25476......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.......515......63......01...............2The first 4 rows are the same policy but with 2 different states. So out of the first 4 rows, 3 are the same so there should be 2 rows set to 0. The bottom 2 rows are the same so 1 of the premiums should be set to 0. I want the table to look like this:Policy.............Premium...Class...State...Entity NumberADC-WC-0010005-0.....25476......63......31...............1ADC-WC-0010005-0.........0......63......31...............2ADC-WC-0010005-0.........0......63......31...............3ADC-WC-0010005-0......1457......63......29...............4ADC-WC-0010092-1......2322......63......37...............1ADC-WC-0010344-0.......515......63......01...............1ADC-WC-0010344-0.........0......63......01...............2Thank you again for the help. It is really appreciated.
Try this:-UPDATE tSET t.Premium=0FROM(SELECT ROW_NUMBER() OVER (PARTITION BY Policy,Premium ORDER BY EntityNumber) AS RowNo,*FROM YourTable)tWHERE t.RowNo <>1
It seems to have worked! Thank you visakh16 for all of your help. You have come through for me in the past and I really appreciate it. Thank you as well to the others for all the help. This forum is awesome!!!
You're welcome . Glad that i could help u on this. |
 |
|
|
|