--根據主鍵生成
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*/
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*/
也可以根据某个值如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
也就是说是从Access中连接SQL,然后得到一个表,将该表的记录插入到Access的表中
使用的是Select * into accessTable from sqlTable