如果这些参数要作为表提示,则需要使用?

Sql Server 存储过程报错 为不是函数的对象 'account' 提供了参数。

create procedure bank_pro @ids varchar(10)
as
declare 
@bid varchar(10),
@bname varchar(20),
@baddr varchar(30),
@bcity varchar(30),
@sums money,
@counts int,
@SQL varchar(500)
declare @curs cursor
--select @sums = sum(a_balance) from account where a_bank_num = @ids;
--select @counts=count(a_bank_num) from account where a_bank_num=@ids
set @curs=cursor scroll dynamic
for
select b.b_id,b.b_name,b.b_address,b.b_city,sum(a.a_balance),count(a.a_id)
from bank b left join account a on b.b_id=a.a_bank_num 
where b.b_id = @ids
group by b.b_id,b.b_name,b.b_address,b.b_city
open @curs
fetch next from @curs into @bid,@bname,@baddr,@bcity,@sums,@counts
while(@@fetch_status=0)
begin
print '编号 '+'名称 '+'地址 '+'城市 '+'总金额 '+'账户数 '
print @bid+@bname+@baddr+@bcity+convert(varchar(20),@sums)+' '+convert(varchar(20),@counts)
fetch next from @curs into @bid,@bname,@baddr,@bcity,@sums,@counts
if(@sums<1000000)
begin 
set @SQL='insert into account() values(''1010'',''天天'',''60000'',''2012-11-23'','''+@ids+''')'
print('该银行总金额少于一百万') 
print(@SQL+'已执行')
exec(@SQL)
end
if(@counts=0)
-- else if(@counts=0)
begin
print('该银行不存在用户')
set @SQL='delete from bank with b_id='''+@ids+''''
print(@SQL+'已执行')
print('该银行已被删除')
exec(@SQL)
end
end;

一只甜甜圈
浏览 168回答 1
1回答

繁星淼淼

declare curs cursorforselect b.b_id,b.b_name,b.b_address,b.b_city,sum(a.a_balance),count(a.a_id)from bank b left join account a on b.b_id=a.a_bank_num&nbsp;where b.b_id = @idsgroup by b.b_id,b.b_name,b.b_address,b.b_cityopen cursfetch next from curs into @bid,@bname,@baddr,@bcity,@sums,@countswhile(@@fetch_status=0)beginprint '编号 '+'名称 '+'地址 '+'城市 '+'总金额 '+'账户数 'print @bid+@bname+@baddr+@bcity+convert(varchar(20),@sums)+' '+convert(varchar(20),@counts)fetch next from @curs into @bid,@bname,@baddr,@bcity,@sums,@countsif(@sums<1000000)begin&nbsp;set @SQL='insert into account() values(''1010'',''天天'',''60000'',''2012-11-23'','''+@ids+''')'print('该银行总金额少于一百万')&nbsp;print(@SQL+'已执行')exec(@SQL)endif(@counts=0)-- else if(@counts=0)beginprint('该银行不存在用户')set @SQL='delete from bank with b_id='''+@ids+''''print(@SQL+'已执行')print('该银行已被删除')exec(@SQL)endCLOSE cursDEALLOCATE cursend
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server