日期:2014-05-18  浏览次数:20479 次

新手请教存储过程的赋值!谢了~~!
请加大家一个问题,我在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

------解决方案--------------------
SQL code
create proc proc_name
@customerAccount varchar(100),
@flg  int output
as
if exists(  
select 1
from Table1 t1, Table2 t2
where t2.AcctMnc = @customerAccount
and t2.BC = t1.BC
and t2.AC = t1.AC and t1.IFlg in(1,2)
)
set @flg=1
else 
set @flg=0