求 access insert 语句 超简单...

来源:百度知道 编辑:UC知道 时间:2024/06/21 21:36:30
tabel1 字段:id name num
tabel2 字段:id name
知道 label2 的 name
要添加 label2 的 id 进 tabel1

insert into tabel1 (id,name,num) values ((select id from tabel2 where name='a'),'b',1)
不懂怎么写,这个一直错误.用变量好像好不行.
有没有用一条SQL语句就行了的呀?郁闷...

可以先开一个recordset对象对打开的数据库中table2根据label2但值进行查询,另一个变量(cid)存储查询出来的id值,然后关闭该recordset,继续建立另一个recordset对象,进行对table1的写任务.

insert into table1(id,name,num) values(cid,'b',1)