新增一条记录,其中一个字段值要等于该记录的自动编号值

covien 2004-04-06 05:50:33
新增一条记录,其中一个字段值要等于该记录的自动编号值。
SQL语句怎么写呢?

我这样写的出错了:
sql="Insert Into news(title, content,pid) Values ('" &sColumn&"', '"&sFileURL&"', id)"
...全文
67 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
covien 2004-04-06
  • 打赏
  • 举报
回复
superdullwolf
你那两个方法都在用在MSSQL里的吧。
我用的是ACCESS

回whyslr:
你那个不行,新增记录的PID和ID不会相等

回QQgenie:
我插入记录是用的connection.execute

谢谢大家的帮忙。
我以这样的方法实现了:
sql="Insert Into news(title, content) Values ('" &sT&"', '"&sC&"')"
conn.execute sql
sql="update news set pID=id where id=(select MAX(ID) from news)"
conn.execute sql
QQgenie 2004-04-06
  • 打赏
  • 举报
回复
rs.update增加后,
id = rs("id")
sql="update news set pID=id where id="&id
whyslr 2004-04-06
  • 打赏
  • 举报
回复
execute("select maxid as a from news")
id=a
sql="Insert Into news(title, content,pid) Values ('" &sColumn&"', '"&sFileURL&"', id)"
超级大笨狼 2004-04-06
  • 打赏
  • 举报
回复
sql="Insert Into news(title, content,pid) Values ('" &sColumn&"', '"&sFileURL&"', scope_identity())"
超级大笨狼 2004-04-06
  • 打赏
  • 举报
回复
sql="Insert Into news(title, content,pid) Values ('" &sColumn&"', '"&sFileURL&"', @@identity)"

covien 2004-04-06
  • 打赏
  • 举报
回复
我选增加了。
然后
sql="update news set pID=id where id=max(id)"
可是条件部分错了。
xieyj 2004-04-06
  • 打赏
  • 举报
回复
先新增后再 update
jinhaiou 2004-04-06
  • 打赏
  • 举报
回复
要用事务处理和applicatioin,取最大值。

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧