新手请教存储过程的赋值!谢了~~!
请加大家一个问题,我在t1中找IFlg字段,当IFlg值为1或者2时,@flg设定为1,否则@flg设定为0,
最后把@flg做为返回值返回到调用此存储过程处。
请问像我这样写对不对?请各位高手指教!!!
谢了!!
begin
declare @i varchar(10)
declare @flg int
select @i = IFlg
from Table1 t1, Table2 t2
where t2.AcctMnc = @customerAccount
and t2.BC = t1.BC
and t2.AC = t1.AC
if(@i = '1' || @i = '2')
set @flg = 1
else
set @flg = 0
select @flg flg
end
go
[解决办法]
create proc proc_name@customerAccount varchar(100),@flg int outputasif exists( select 1from Table1 t1, Table2 t2where t2.AcctMnc = @customerAccountand t2.BC = t1.BCand t2.AC = t1.AC and t1.IFlg in(1,2))set @flg=1else set @flg=0