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 2000 Forums
 SQL Server Development (2000)
 what's the best way to do this with tsql?

Author  Topic 

SunnyDee
Yak Posting Veteran

79 Posts

Posted - 2007-02-12 : 14:36:05
Below is what the recordset should look like, with the second column value incrementing by 1 for every repeated value in column 1.

4748 1
4748 2
4748 3
4748 4
4749 1
4749 2
4749 3
4749 4
4749 5
4750 1
4750 2
4750 3
4750 4
4750 5

what is the best way to make sure future updates to this table follow this format? The original recordset is Excel and we are moving to SQL Server.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 14:38:53
It depends on where the values come from, what to start with for first new value in new group.
We need some more information.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-02-12 : 15:54:29
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx
point 1



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-13 : 01:15:39
[code]-- prepare sample data
declare @t table (grp int, value int)

insert @t
select 4748, 1 union all
select 4748, 2 union all
select 4749, 1 union all
select 4750, 1 union all
select 4750, 2 union all
select 4750, 3

select grp,
value
from @t
order by grp,
value

-- show the new values
select x.grp,
x.value
from (
select grp,
max(value) + 1 as Value
from @t
group by grp
union all
select grp,
value
from @t
) as x
order by x.grp,
x.value[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SunnyDee
Yak Posting Veteran

79 Posts

Posted - 2007-02-13 : 14:10:19
Thank you. I was able to use your code and modify it slightly to fit my needs.
Go to Top of Page
   

- Advertisement -