--根據主鍵生成
if object_id('tb') is not null drop table tb
go
create table tb(ID int primary key,[name] varchar(10))
insert tb select 1, 'A'
insert tb select 5, 'B'
insert tb select 3, 'C'
insert tb select 11,'E'
select *,流水号=(select count(*)+1 from tb where id<t.id) from tb t
/*ID          name       流水号         
----------- ---------- ----------- 
1           A          1
3           C          2
5           B          3
11          E          4*/

解决方案 »

  1.   

    自增列
    也可以根据某个值如ID来获取.select * , px = (select count(1) from tb where id < t.id) + 1 from tb t
    select * , px = (select count(1) from tb where id > t.id) + 1 from tb t
      

  2.   

    但是我的这个表是从SQL里面查询出来的,而且SQL里面ID字段是Guid类型的。
    也就是说是从Access中连接SQL,然后得到一个表,将该表的记录插入到Access的表中
    使用的是Select * into accessTable from sqlTable