高手请进,在线等待!!!

wy8010 2003-09-12 10:15:43
请问要怎样解决以下问题,高手请指点,在线等待,急啊!
写一条记录进table1,读table2的ID号,如果table2有10个ID(01,02,03,...,10)则该条记录自动增长9条(以table2的ID号为主,如果是3个ID,则自增2条),同时
table2的ID号还要写入table1的ID号中,实例如下:
写一条为test的记录进table1,
table2
ID
01
02
03
04
05
table1
ID Name
01 test
02 test
03 test
04 test
05 test
...全文
48 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wy8010 2003-09-14
  • 打赏
  • 举报
回复
问题已解决,多谢各位!
cqfeng 2003-09-12
  • 打赏
  • 举报
回复
其实也不是很难,你把整个过程弄清楚就行了
1. 写记录进table1,这条里面有id和name
2. 查询table2,得到不包含上面id的其他id
3. 将name和table2的id写入table1
wy8010 2003-09-12
  • 打赏
  • 举报
回复
cqfeng():用的是Access数据库,能提供好的解决方案吗???
cqfeng 2003-09-12
  • 打赏
  • 举报
回复
收回上面的建议 ^_^
cqfeng 2003-09-12
  • 打赏
  • 举报
回复
假如是SQL Server,你可以考虑一下trigger

在写入记录进table1的时候,计算table2的id总数,根据这个总数循环写入table1
wy8010 2003-09-12
  • 打赏
  • 举报
回复
vivisogood(新人类):能详细一点吗
vivisogood 2003-09-12
  • 打赏
  • 举报
回复
做个循环啊. 判断id为几就执行几次插入操作啊!
wy8010 2003-09-12
  • 打赏
  • 举报
回复
整段代码
<%
'打开数据库显示
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from YearHand"
rs.open sql,conn,1
if request("Save")="增加" then
errorinfo=""
ItemID=trim(request.form("ItemID"))
if strlength(ItemID)<>3 then
errorinfo=errorinfo&"编号必须为3位数字!<br>"
end if
Years=request.form("Years")
ItemID=request.form("ItemID")
SortName=request.form("SortName")
EvaluateItem=request.form("EvaluateItem")
RatingPoint=request.form("RatingPoint")
GradeStandard=request.form("GradeStandard")
if errorinfo="" then
'判断是否有与申请的用户名相同的
on error resume next
set conn=opendb("oabusy","conn","accessdsn")
conn.BeginTrans
set rs=server.createobject("adodb.recordset")
sql="select * from YearHand where ItemID=" & sqlstr(ItemID)
rs.open sql,conn,1
if not rs.eof and not rs.bof then
%>
<%
'打开数据库显示
set conn=opendb("oabusy","conn","accessdsn")
set rss=server.createobject("adodb.recordset")
sql="select StatID from Department "
rss.open sql,conn,1

%>
<%
else
while not rss.eof
sql = "Insert Into YearHand (Years,StatID,SortName,EvaluateItem,ItemID,RatingPoint,GradeStandard) Values( "
sql = sql & rss.f & ", "
sql = sql & SqlStr(Years) & ", "
sql = sql & SqlStr(SortName) & ", "
sql = sql & SqlStr(EvaluateItem) & ", "
sql = sql & SqlStr(ItemID) & ", "
sql = sql & SqlStr(RatingPoint) & ", "
sql = sql & SqlStr(GradeStandard) & ")"
conn.Execute(sql)
conn.committrans
rss.move(1)
wend

end if
%>
wy8010 2003-09-12
  • 打赏
  • 举报
回复
二位请看代码,我用这种方法出现死循环,不停的写入同一条数据,
<%
'打开数据库显示
set conn=opendb("oabusy","conn","accessdsn")
set rss=server.createobject("adodb.recordset")
sql="select StatID from Department "
rss.open sql,conn,1

%>
<%
else
while not rss.eof
sql = "Insert Into YearHand (Years,StatID,SortName,EvaluateItem,ItemID,RatingPoint,GradeStandard) Values( "
sql = sql & rss.f & ", "
sql = sql & SqlStr(Years) & ", "
sql = sql & SqlStr(SortName) & ", "
sql = sql & SqlStr(EvaluateItem) & ", "
sql = sql & SqlStr(ItemID) & ", "
sql = sql & SqlStr(RatingPoint) & ", "
sql = sql & SqlStr(GradeStandard) & ")"
conn.Execute(sql)
conn.committrans
rss.move(1)
wend

end if
%>
wy8010 2003-09-12
  • 打赏
  • 举报
回复
二位能详细一点吗,
tigerwen01 2003-09-12
  • 打赏
  • 举报
回复
insert into table1 where id in(select id from table2)
wy8010 2003-09-12
  • 打赏
  • 举报
回复
不知是我说得不够详细,还是你理解错了,我的意思是写一条记录就等于增加多条记录,以table2的ID为主,ID有多少就自增多少
Brookes 2003-09-12
  • 打赏
  • 举报
回复
insert into table1 select id,'test' from table2

28,390

社区成员

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

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