Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ARTYB
Starting Member
4 Posts |
Posted - 2013-07-17 : 11:00:08
|
I have a table where i have a multitude of columns.idnum,diagnosiscode,order_of_diagnosis,POA_Flag000000000000001|234|01|Y000000000000001|800|02|Y000000000000001|E344|03|Y000000000000001|667|04|Y000000000000001|900|05|Y000000000000001|234|06|Y000000000000001|800|07|Y000000000000001|E344|08|Y000000000000001|667|09|Y000000000000001|900|10|Y000000000000001|288|11|Y000000000000001|4800|12|Y000000000000001|G887|13|Y000000000000001|667|14|Y000000000000001|900|15|YI am trying to write a select distinct query that will return each group with ONLY unique diagnosiscode, and renumbering as applicable so they stay in thier original order. Thanks for any all assistance in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 11:20:27
|
So what should be the output?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
ARTYB
Starting Member
4 Posts |
Posted - 2013-07-17 : 11:36:32
|
Output should be the same format as input :D |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 11:58:52
|
Sorry i didnt get you. How do you want numbering to come?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
ARTYB
Starting Member
4 Posts |
Posted - 2013-07-17 : 12:06:40
|
Here is the example content prior to removing the duplicate values000000000000001|234|01|Y000000000000001|800|02|Y000000000000001|E344|03|Y000000000000001|667|04|Y000000000000001|900|05|Y000000000000001|234|06|Y - to be removed as redundant000000000000001|800|07|Y - to be removed as redundant000000000000001|E344|08|Y - to be removed as redundant000000000000001|667|09|Y - to be removed as redundant000000000000001|900|10|Y - to be removed as redundant000000000000001|288|11|Y000000000000001|4800|12|Y000000000000001|G887|13|Y000000000000001|667|14|Y - to be removed as redundant000000000000001|900|15|Y - to be removed as redundantThis would be the final output format:000000000000001|234|01|Y000000000000001|800|02|Y000000000000001|E344|03|Y000000000000001|667|04|Y000000000000001|900|05|Y000000000000001|288|06|Y (New Value and in ordinal order)000000000000001|4800|07|Y(New Value and in ordinal order) |
|
|
ARTYB
Starting Member
4 Posts |
Posted - 2013-07-17 : 12:07:55
|
quote: Originally posted by ARTYB Here is the example content prior to removing the duplicate values000000000000001|234|01|Y000000000000001|800|02|Y000000000000001|E344|03|Y000000000000001|667|04|Y000000000000001|900|05|Y000000000000001|234|06|Y - to be removed as redundant000000000000001|800|07|Y - to be removed as redundant000000000000001|E344|08|Y - to be removed as redundant000000000000001|667|09|Y - to be removed as redundant000000000000001|900|10|Y - to be removed as redundant000000000000001|288|11|Y000000000000001|4800|12|Y000000000000001|G887|13|Y000000000000001|667|14|Y - to be removed as redundant000000000000001|900|15|Y - to be removed as redundantThis would be the final output format:000000000000001|234|01|Y000000000000001|800|02|Y000000000000001|E344|03|Y000000000000001|667|04|Y000000000000001|900|05|Y000000000000001|288|06|Y (New Value and in ordinal order)000000000000001|4800|07|Y (New Value and in ordinal order)000000000000001|G887|08|Y (New Value and in ordinal order)
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 12:28:57
|
[code]SELECT idnum,diagnosiscode,order_of_diagnosis,POA_FlagFROM(SELECT ROW_NUMBER() OVER (PARTITION BY idnum,diagnosiscode ORDER BY order_of_diagnosis ASC) AS RN,*FROM Table)tWHERE RN=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|