开发者

Increment field in Select statement

I have some data which i dont have a group statement in, and would not like to have a group statement in. But i would like to have an increment field so i can can do a reporting services zebra table.

So, how do i turn this data:

region    country     office    somedata     someotherdata
EUROPE    Austria     Vienna    12           2
ASIA      India       Delhi     22           4

Into

region    country     office    somedata     someotherdata     IncField
EUROPE    Austria     Vienna    12           2                 1
ASIA  开发者_如何学运维    India       Delhi     22           4                 2


you can try using the

SELECT ROW_NUMBER() OVER (ORDER BY SomeData) AS IncField
, *
FROM TableName

[Edit] Works with Sql Server 2005 and 2008


In SQL Server 2005 and above:

SELECT  *, ROW_NUMBER() OVER (ORDER BY someotherdata) AS IncField
FROM    mytable


Insert your data into a temp table, which has an additional field (IDENTITY) as an incremental counter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜