写sp的sql语句
那位高手可以介绍下关于过程存储的SQL语句的写法。
很急,谢谢。
参考答案:create procedure proc_newaccount
@name varchar(10),
@pid varchar(20),
@telephone varchar(20),
@openmoney money,
@savingtype varchar(10),
@address varchar (50)='' --默认
as
declare @error int
set @error=0
declare @cardid varchar(19)
exec proc_rand @cardid output
set @error=@error+@@error
while exists (select * from cardinfo where cardid=@cardid)
exec proc_rand @cardid output
set @error=@error+@@error
insert into userinfo (customername,pid,telephone,address) values (@name,@pid,@telephone,@address)
set @error=@error+@@error
declare @customerid int
select @customerid=customerid from userinfo where customername=@name
set @error=@error+@@error
insert into cardinfo (cardid,savingtype,openmoney,balance,customerid) values (@cardid,@savingtype,@openmoney,@openmoney,@customerid)
set @error=@error+@@error
declare @opendate datetime
select @opendate=opendate from cardinfo where cardid=@cardid
set @error=@error+@@error
if @error=0
begin
print '开户成功! 您的卡号为:'+@cardid
print '开户日期:'+convert(varchar(25),@opendate)+' 开户金额:'+convert(varchar(20),@openmoney)
end
else
print '开户失败,请重新输入!'
go
你自己去理解一下,相信对你有帮助!!!