|
IF OBJECT_ID('tb') IS NOT NULL DROP TABLE tb
GO
CREATE TABLE tb
(
FDate datetime ,
FPeriod int,
FNum int,
FEntryID int
)
GO
INSERT TB ( FDate, FPeriod, FNum )
SELECT '2009-1-1', 1, 1 union all
SELECT '2009-1-1', 1, 1 union all
SELECT '2009-1-1', 1, 1 union all
SELECT '2009-1-1', 1, 1 union all
SELECT '2009-1-3', 1, 2 union all
SELECT '2009-1-3', 1, 2 union all
SELECT '2009-1-3', 1, 2 union all
SELECT '2009-1-4', 1, 4 union all
SELECT '2009-1-4', 1, 4
--查询
--如果update可以
declare @i int,@fnum int
set @i=0
update tb
set FEntryID=@i,
@i=case when @fnum = fnum then @i+1 else 0 end,
@fnum=fnum
go
--
select * from tb
DROP TABLE tb;
|
|