CREATE TABLE [dbo].[CustomerTrack](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [CustomerID] [uniqueidentifier] NULL,
 [Channel] [int] NULL,
 [OrderIndex] [int] NULL,
 [Value] [nvarchar](50) NULL,
 CONSTRAINT [PK_CustomerTrack] PRIMARY KEY CLUSTERED
(
 [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
 
---------------
 
上表增删改之后,下述脚本更新orderindex
with r_SomeTable
as
(
select *
, row_number() over(partition by IDCol order by ValueCol) as rnk
from SomeTable
)
update r_SomeTable
set RANKCol = rnk
posted on 2011-03-21 20:05  默西塞德  阅读(494)  评论(0编辑  收藏  举报