Contents

1
2


1 #

豈覯 蠏狩 螻豺 譯殊願鹸 讌襷.. 伎覲企 螳.

2 #

use tempdb
go

--豐蠍一誤
create table dbo.Sequence(seq int)
insert dbo.Sequence values(1)
go

create proc dbo.usp_Sequence
	@option tinyint --1:currval, 2:nextval, 
,	@increment int = 1
as
declare @seq int;

if @option = 2
begin
	update dbo.Sequence
	set @seq = seq = seq + @increment;
end else
	set @seq = (select top 1 seq from dbo.Sequence);

return @seq;
go

--: 螳
declare @seq int
exec @seq = dbo.usp_Sequence 1
select @seq

--: れ螳
declare @seq int
exec @seq = dbo.usp_Sequence 2
select @seq