注册 登录
编程论坛 SQL Server论坛

如何用存储过程添加新记录?我的怎么加不进去?(以前没用过 - -!)

yzwt2004 发布于 2007-04-02 10:37, 1475 次点击

create proc nameb
@btt varchar(50),
@hyy varchar(50)
as
begin
for i=1 to 200
insert into new_db(bt,hy) values(@btt,@hyy)
next

end
go

注:在执行编译时提示
服务器: 消息 156,级别 15,状态 1,过程 nameb,行 6
在关键字 'for' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,过程 nameb,行 8
第 8 行: 'next' 附近有语法错误。

asp页面执行代码:
<!--#include file="conn.asp" -->

<%
set rs=server.createobject("adodb.recordset")
sql = "exec namea '添加主题"&i&"','添加内容"&i&"'"
rs.open sql,conn,3,3
%>

以前没过,谁能给我写个全面的,谢谢

4 回复
#2
xiyou4192007-04-02 18:27
create proc nameb
(
@btt varchar(50),
@hyy integer
)
as
declare @count integer
set @count=1
begin
while (@count<200)
insert into new_db(bt,hy) values(@btt,@hyy)
end
go
#3
yzwt20042007-04-03 10:24
以下是引用xiyou419在2007-4-2 18:27:00的发言:
create proc nameb
(
@btt varchar(50),
@hyy integer
)
as
declare @count integer '这个表是什么意思
set @count=1
begin
while (@count<200) '在sql里就循环就可以了?没有结速循环的标识吗
insert into new_db(bt,hy) values(@btt,@hyy)
end
go

真的非常感谢楼上

不过有几点不明白,请帮我解说一下

#4
棉花糖ONE2007-04-03 12:07
他这个是死循环
end 前面加上一句 select @count=@count+1

declare @count integer 这个是声明一个整型变量
#5
xiyou4192007-04-03 18:11

呵呵,粗心,忘了给记数变量加1了.
嘿嘿,还是棉花细心啊~~~~~~~~~~

1