Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
something like this?declare @num intset @num = 0DECLARE @table TABLE (col1 int,Col2 int)INSERT INTO @table SELECT 1,null union allSELECT 1,null union allSELECT 1,null union allSELECT 1,null UPDATE @table SET @num = col2 = @num+ 1select * from @tableJimEveryday I learn something that somebody else already knew
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts
Posted - 2010-08-12 : 15:18:18
Or like how Tara mentioned, using ROW_NUMBER()
DECLARE @table TABLE (col1 int,Col2 int)INSERT INTO @table SELECT 1,null union allSELECT 1,null union allSELECT 1,null union allSELECT 1,null UPDATE tSET t.Col2 = t.seqfrom (select row_number() over(order by col1) as seq ,* from @table) t
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2010-08-13 : 11:01:11
It is better to have it as part of SELECT statement so that you dont need to update everytime data are added to the tableMadhivananFailing to plan is Planning to fail