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
 Transact-SQL (2000)
 Creating continous numbers in a column-ASAP

Author  Topic 

dina
Starting Member

1 Post

Posted - 2006-05-31 : 02:21:59
hai ,
I want to populate a column in a table with continous numbers starting from 1 to 100 using sql query

Any way to da that
Regards
Dina

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-31 : 02:28:20
yes. Make use of this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47685&SearchTerms=F_TABLE_NUMBER_RANGE


KH

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-31 : 02:39:51
or if you have a datetime or any column that increments...

update table_name
set columnname=(select count(*) from table_name where incrementing_col<a.incrementing_col) + 1
from table_name a

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-31 : 04:24:18
Where do you want to show the data?
If you use front end application, do numbering there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-05-31 : 06:45:12
Another option...

--data
declare @t table (x varchar(10), y int)
insert @t (x)
select 'this'
union all select 'is'
union all select 'some'
union all select 'data'

--calculation - note that this method will not guarantee the order
declare @i int
set @i = 0
update @t set @i = @i + 1, y = @i

select * from @t

--results
x y
---------- -----------
this 1
is 2
some 3
data 4


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -