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 2008 Forums
 Transact-SQL (2008)
 View

Author  Topic 

abhi234u
Starting Member

1 Post

Posted - 2010-04-30 : 10:43:08
Hi there,

We have a small view to create. I have columns

Year Month recordnumber County sales revenue
2008 jan 12345 xyz $100
2008 Feb 12345 TRW $200


I have to adda new column which shows unique recordnumber's. It should show 1 for jan, 0 for february and so on.

Any inputs would be appreciated.

Thanks

Abhi

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-30 : 10:48:08

Is this?

select row_number() over (order by year) as sno, * from your_table

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-01 : 04:23:22
or this?

select row_number() over (partition by year order by case Month when 'Jan' then 1 when 'Feb' then 2 ....when 'Dec' then 12 end asc) as sno, * from your_table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-07 : 03:37:09
or

select row_number() over (order by month+cast(year as varchar(4))) as sno, * from your_table

Madhivanan

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

- Advertisement -