create function ... @主鍵
return int
as
...
select identity(int,1,1) as id,基他字段
into #新表
from 你的表 declare @i int
select @i=id
from #新表
where 主鍵=@主鍵 drop table #新表
return(@i) ...
return int
as
...
select identity(int,1,1) as id,基他字段
into #新表
from 你的表 declare @i int
select @i=id
from #新表
where 主鍵=@主鍵 drop table #新表
return(@i) ...
--如果是按主键从小到大来确定记录的位置,可以用这样的函数create function f_rownum(@主键 varchar(10))
returns int
as
begin
return(select sum(1) from 表 where 主键<=@主键)
end
go--调用
select dbo.f_rownum('asdfa')
returns int
as
begin
declare @table table (id int identity(1,1),unit varchar(10))
insert into @table
select unit
from tabTest declare @i int
select @i=id
from @table
where unit=@A
return(@i)end