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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DENSE_RANK ( )

Author  Topic 

ben_53
Yak Posting Veteran

67 Posts

Posted - 2011-08-25 : 20:28:41
I have my_table
with 3 columns

col1 = refnum
col2 = seqnum

now there can be 'n' ref numbers
if certain condition is met and we find ref num 3, then the order starts from 3 for seqnum
here is sample data: (there is match for say refnum = 02)
refnum seqnum
01 02
01 02
01 02
02 01
02 01
03 03
03 03
03 03
03 03 .......


so if condition finds ref num = 2, then in seqnum, 2 becomes 1 and 1 becomes 2 and so on...

Another example: (condition met at refnum = 3)

refnum seqnum
01 02
02 03
02 03
02 03
03 01
03 01
04 04
04 04
05 05...

kindly note that there can be 1000's of ref numbers I cant hardcode it.
needs a logic. THANKS







khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-25 : 21:21:03
quote:
I have my_table
with 3 columns

You only show us 2 column. What's the 3rd column ?

quote:
if certain condition is met and we find ref num 3, then the order starts from 3 for seqnum

what condition ? ref num 3 is the input ?

Really don't quite understand what do you want here. What you have posted is the sample data right ? Can you show us the corresponding expected result ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -