SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need Assistance
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ARTYB
Starting Member

USA
4 Posts

Posted - 07/17/2013 :  11:00:08  Show Profile  Reply with Quote
I have a table where i have a multitude of columns.
idnum,diagnosiscode,order_of_diagnosis,POA_Flag

000000000000001|234|01|Y
000000000000001|800|02|Y
000000000000001|E344|03|Y
000000000000001|667|04|Y
000000000000001|900|05|Y
000000000000001|234|06|Y
000000000000001|800|07|Y
000000000000001|E344|08|Y
000000000000001|667|09|Y
000000000000001|900|10|Y
000000000000001|288|11|Y
000000000000001|4800|12|Y
000000000000001|G887|13|Y
000000000000001|667|14|Y
000000000000001|900|15|Y

I 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

India
52309 Posts

Posted - 07/17/2013 :  11:20:27  Show Profile  Reply with Quote
So what should be the output?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ARTYB
Starting Member

USA
4 Posts

Posted - 07/17/2013 :  11:36:32  Show Profile  Reply with Quote
Output should be the same format as input :D
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/17/2013 :  11:58:52  Show Profile  Reply with Quote
Sorry i didnt get you. How do you want numbering to come?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ARTYB
Starting Member

USA
4 Posts

Posted - 07/17/2013 :  12:06:40  Show Profile  Reply with Quote
Here is the example content prior to removing the duplicate values

000000000000001|234|01|Y
000000000000001|800|02|Y
000000000000001|E344|03|Y
000000000000001|667|04|Y
000000000000001|900|05|Y
000000000000001|234|06|Y - to be removed as redundant
000000000000001|800|07|Y - to be removed as redundant
000000000000001|E344|08|Y - to be removed as redundant
000000000000001|667|09|Y - to be removed as redundant
000000000000001|900|10|Y - to be removed as redundant
000000000000001|288|11|Y
000000000000001|4800|12|Y
000000000000001|G887|13|Y
000000000000001|667|14|Y - to be removed as redundant
000000000000001|900|15|Y - to be removed as redundant


This would be the final output format:

000000000000001|234|01|Y
000000000000001|800|02|Y
000000000000001|E344|03|Y
000000000000001|667|04|Y
000000000000001|900|05|Y
000000000000001|288|06|Y (New Value and in ordinal order)
000000000000001|4800|07|Y
(New Value and in ordinal order)
Go to Top of Page

ARTYB
Starting Member

USA
4 Posts

Posted - 07/17/2013 :  12:07:55  Show Profile  Reply with Quote
quote:
Originally posted by ARTYB

Here is the example content prior to removing the duplicate values

000000000000001|234|01|Y
000000000000001|800|02|Y
000000000000001|E344|03|Y
000000000000001|667|04|Y
000000000000001|900|05|Y
000000000000001|234|06|Y - to be removed as redundant
000000000000001|800|07|Y - to be removed as redundant
000000000000001|E344|08|Y - to be removed as redundant
000000000000001|667|09|Y - to be removed as redundant
000000000000001|900|10|Y - to be removed as redundant
000000000000001|288|11|Y
000000000000001|4800|12|Y
000000000000001|G887|13|Y
000000000000001|667|14|Y - to be removed as redundant
000000000000001|900|15|Y - to be removed as redundant


This would be the final output format:

000000000000001|234|01|Y
000000000000001|800|02|Y
000000000000001|E344|03|Y
000000000000001|667|04|Y
000000000000001|900|05|Y
000000000000001|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)


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/17/2013 :  12:28:57  Show Profile  Reply with Quote

SELECT idnum,diagnosiscode,order_of_diagnosis,POA_Flag
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY idnum,diagnosiscode ORDER BY order_of_diagnosis ASC) AS RN,*
FROM Table
)t
WHERE RN=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000