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 |
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2013-10-13 : 20:52:02
|
Hi,I have the following data:POL# POL_EFF_DATE123 1-1-2012123 1-1-2012123 1-1-2012123 1-1-2013123 1-1-2013456 1-1-2012456 1-1-2012456 1-1-2013456 1-1-2013I want to add sequence number to each group with same Pol# and Effective Date like this:POL# POL_EFF_DATE Seq123 1-1-2012 1123 1-1-2012 1123 1-1-2012 1123 1-1-2013 2123 1-1-2013 2456 1-1-2012 1456 1-1-2012 1456 1-1-2013 2456 1-1-2013 2is there a set based function to accomplish this in SQL 2008?thanksScott |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-10-14 : 01:07:11
|
Declare @Table Table (POL# int,POL_EFF_DATE varchar(20))insert @Table Select 123,'1-1-2012'union all Select 123,'1-1-2012'union all Select 123,'1-1-2012'union all Select 123,'1-1-2013'union all Select 123,'1-1-2013'union all Select 456,'1-1-2012'union all Select 456,'1-1-2012'union all Select 456,'1-1-2013'union all Select 456,'1-1-2013'Select *,Dense_Rank() Over (Partition By POL_EFF_DATE Order by POL#) AS Seq From @Tableveeranjaneyulu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-14 : 01:54:21
|
it should beSelect *,Dense_Rank() Over (Partition By [POL#] Order by POL_EFF_DATE) AS Seq From @Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
scabral7
Yak Posting Veteran
57 Posts |
Posted - 2013-10-14 : 12:42:40
|
thanks visakh16,that worked! |
|
|
|
|
|
|
|