| Author |
Topic |
|
werhardt
Constraint Violating Yak Guru
270 Posts |
Posted - 2008-02-01 : 09:53:35
|
| I need help figuring out how to consolidate duplicate records. For example We have a termed client same info until you get to the number of live because they are different. How can I take a both these lines and have them combined. There are other clients that are dups too. Please help if you can.25-0016 10270-00000-00013 WEXFORD HEALTH SOURCES 12/31/2007 47 25-0016 10270-00000-00013 WEXFORD HEALTH SOURCES 12/31/2007 75 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-01 : 09:58:07
|
| This really depends on how to want them. We need more info on how you want this to be done like which value you are interested in i.e 47 or 75 can you explain what you are really looking at to attain with some sample data and table structure? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-02-01 : 10:12:48
|
How do you want to combine them ? What's the end result like ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
werhardt
Constraint Violating Yak Guru
270 Posts |
Posted - 2008-02-01 : 10:13:50
|
| Here is a little more of an explanation. We need to pull the most recent enrollment Termdate in the report. So we would want to only pull the first line of data.Mas90# Client Number Client Name TermDate Lives Enrollment live Termdate25-0016 10270-00000-00013 WEXFORD HEALTH SOURCES 12/31/2007 47 12/31/200725-0016 10270-00000-00013 WEXFORD HEALTH SOURCES 12/31/2007 75 05/31/2006 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-01 : 10:17:03
|
| select [Mas90#] ,[Client Number], [Client Name], TermDate, [Lives Enrollment], Max([live Termdate]) as live Termdate from yourtablegroup by [Mas90#] ,[Client Number], [Client Name], TermDate, [Lives Enrollment]MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-01 : 10:31:36
|
| or if SQL 2005:-SELECT * FROM(SELECT ROW_NUMBER() OVER(PARTITION BY Mas90# Client Number Client Name TermDate ORDER BY Termdate DESC) as RowNo,other fieldsFROM Table)tmpWHERE tmp.RowNo=1 |
 |
|
|
werhardt
Constraint Violating Yak Guru
270 Posts |
Posted - 2008-02-01 : 11:09:10
|
| I have another example of one. We had to join the parent client together so we did this and it worked. Is there a generic one I can use when it comes to other ones? for example ones like this 10270-00000-00013.Here is what fields are what....cli2.cli_lev1 10270.....cli2.cli_lev1 00000....cli2.cli_lev1 00013JOIN cli cli2 ON cli2.cli_lev1 = cli.cli_lev1 AND cli2.cli_lev2 = '00000' AND cli2.cli_lev3 = '00000' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-01 : 11:48:32
|
quote: Originally posted by werhardt I have another example of one. We had to join the parent client together so we did this and it worked. Is there a generic one I can use when it comes to other ones? for example ones like this 10270-00000-00013.Here is what fields are what....cli2.cli_lev1 10270.....cli2.cli_lev1 00000....cli2.cli_lev1 00013JOIN cli cli2 ON cli2.cli_lev1 = cli.cli_lev1 AND cli2.cli_lev2 = '00000' AND cli2.cli_lev3 = '00000'
what do you mean by generic? It all depends on what you want to do with unique valued columns. sometimes you might look for latest records as in this case in some cases first record etc. So it basically boils down to your requirement. |
 |
|
|
|