create table common_info(
name varchar(10),
value int)
insert into common_info values('msg_count', 100)
你的sql应该这么写(用存储过程):
create proc p_ins_alm_msg
@msg_count int out
as
select @msg_count = value from common_info where name = 'msg_count'
update common_info set value = @msg_count+ 1 where name = 'msg_count' and value =
name varchar(10),
value int)
insert into common_info values('msg_count', 100)
你的sql应该这么写(用存储过程):
create proc p_ins_alm_msg
@msg_count int out
as
select @msg_count = value from common_info where name = 'msg_count'
update common_info set value = @msg_count+ 1 where name = 'msg_count' and value =
@msg_count
if @@rowcount = 0
return -1000
insert into table1 (field0)
values(@msg_count)
return 0
go
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124400/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-124400/
本文介绍了一个使用SQL存储过程更新和插入消息计数的示例。首先创建了一个名为common_info的表,包含name和value两个字段,然后通过存储过程检查并更新'msg_count'的值,如果未找到则插入新记录。
630

被折叠的 条评论
为什么被折叠?



