>>I'm trying to generate row numbers for each row returned in my query:
>>
>>
>>SELECT *, (SELECT COUNT(t2.TabId)
>> FROM rbpo.rb_Tabs t2
>> WHERE t2.TabId = t1.TabId ) AS RowNum
>> FROM rbpo.rb_Tabs t1
>> WHERE ParentTabId = @SJTabId
>> ORDER BY RowNum ASC
>>
>>
>>The RowNum is coming back all 1's
>
>
>Ok everyone, I', stil stuck here. I need a row number on each row returned:
>
>
>SELECT *, (SELECT COUNT(t2.TabId)
> FROM rbpo.rb_Tabs t2
> WHERE t2.TabId <= t1.TabId ) AS RowNum
> FROM rbpo.rb_Tabs t1
> WHERE ParentTabId = 47
>
>
>
>This is a minor change from above, but the row numbers are 12, 19, 67, 59, 70 - Not 1,2,3,4,5 as I need.
>
>The reason I need this is that I want to iterate through the rows, pull each row one at a time, change the Parentid, and insert it
>back into the table. Maybe I'm going about this all wrong?
DECLARE @Test TABLE (your field list here from original table, RowNumber int IDENTITY(1,1))
INSERT INTO @Test (fiel list here w/o ROWNUMBER one)
SELECT .....
FROM rbpo.rb_Tabs t1
WHERE ParentTabId = 47
SELECT * FROM @Test
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.