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
 General SQL Server Forums
 New to SQL Server Programming
 adding extra column with ordered no.

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-06-17 : 16:37:56
Hi,
I have created view which only has one column, I would like to order the rows ascending based on the value in the column and also add another column (OGH) and fill the new column from 1 to the size of the rows after setting the first column ascending.

Here is my view where I want to add to order it and add to it another column with number from 1.

ALTER view [dev].[OG]
as
SELECT [geo_orig] OG
FROM [bts].[dev].[geo_master]

GO

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-17 : 16:50:58
ALTER view [dev].[OG] as
SELECT TOP 100 PERCENT [geo_orig] OG, ROW_NUMBER() OVER (ORDER BY [geo_orig]) OGH
FROM [bts].[dev].[geo_master]
ORDER BY [geo_orig]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-20 : 10:50:14
In the original VIEW, you can query it like

SELECT OG,ROW_NUMBER() OVER (ORDER BY [OG]) OGH
FROM OG
ORDER BY OGH

Madhivanan

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

- Advertisement -