帮我看一下我写的两个存储过程,在多台机器同时执行的时候,有可能只执行一句,谢谢帮忙,在线等
下面的两个存储过程是用来给给顾客发会员卡和会员卡冲消费积分金额的,第一个存储过程有时候无法
把变参中的的数据插入tr_customer表中,第二个存储过程,如果是本店卡和当日的信用卡,将从retjels中取xulh,riqi,shoukyh三个字段插入tr_jifen表,然后把retjels中当前xulh的yishj更新为否。但是,如果再多台机器同时写入的时候,此存储过程可能会只运行
create PROCEDURE tr_jifen_pro
(
@cd char(8) ,
@xph char(12) ,
@kh decimal(15,2),
@ky char(6)
--设置变参
)
AS
if not exists --判断下面的select是否返回值,如果不返回值,执行下面的语句,如果返回跳到else
(select 1 from tr_customer where cardno =@cd) --直接判断卡号是否在tr_customer表中
begin
insert into tr_jifen
(cardno,xulh,riqi,shishje,kouhj,jiqrq,shoukyh,jfsky,ontime)
select '非本店卡',xulh,riqi,shishje,@kh,convert(char(10),getdate(),120),shoukyh,@ky,convert(char(10),getdate(),8)
from retjels
where xulh=@xph and yishj='否' --当选定的小票号在retjels中的yishj字段为否,查询纪录插入tr_jifen表
end
else
begin
insert into tr_jifen
(cardno,xulh,riqi,shishje,kouhj,jiqrq,shoukyh,jfsky,ontime)
select @cd,xulh,riqi,shishje,@kh,convert(char(10),getdate(),120),shoukyh,@ky,convert(char(10),getdate(),8)
from retjels
where xulh=@xph and yishj='否' ----当选定的小票号在retjels中的yishj字段为否,查询纪录插入tr_jifen表
update retjels set yishj='是' where xulh=@xph --当选定的小票号在retjels中的yishj字段为是
update tr_jifen set xulh='非本日小票' where jiqrq<>riqi and cardno=@cd
end
select top 10 *
from tr_jifen
where jfsky=@ky
order by ontime desc
GO
上面的存储过程,所用到的表及其结构
retjels中的字段有,xulh,riqi,shoukyh,yishj
tr_customer的表结构
create table tr_customer --创建新tr_customer表
(
xh int identity(1,1),
cardno char(8) not null,
certif_no char(18) not null,
certif char(8) not null,
uname char(8) not null,
sex char(2) null,
phone char(12) null,
fkrq char(10) null
)
tr_jifen表的结构
create table tr_jifen --创建新tr_jifen表
(
cardno char(8) not null,
xulh char(12) not null,
riqi char(10) null,
shishje decimal(15,2) null default 0,
kouhj decimal (15,2) null default 0,
jiqrq char(10) null,
shoukyh char(6) null,
jfsky char(6) null,
ontime char(10) null,
beizhu char(50) null
)