急求存储过程exec获得sql返回值,判断之后不走下一次循环
USE [nature]GO/****** Object: StoredProcedure [dbo].[sc_yz] Script Date: 07/16/2012 09:40:13 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[sc_yz] @fun_table_name as varchar(5000), --参数 @bl int output, --数据使用量 @b_m_return varchar(100) output --返回表名ASBEGINdeclare @bm varchar(300),--表名@m int,--循环1@n int, --循环1@a int,--循环2@b int, --循环2@tj varchar(300),--条件@linshi varchar(300), --临时@sql nvarchar(4000), --sql@b_m_l_s varchar(300) --临时表名set @m=CHARINDEX(';',@fun_table_name) set @n=1 WHILE @m>0 BEGIN set @bm=substring(@fun_table_name,@n,@m-@n) set @n=@m+1 set @m=CHARINDEX(';',@fun_table_name,@n) set @a=CHARINDEX(',',@bm) set @b=1 WHILE @a>0 BEGIN set @linshi=substring(@bm,@b,@a-@b) if @b=1 begin set @sql='select @bl = count(*) from '+@linshi set @b_m_l_s = @linshi end else begin set @sql+=' '+@linshi end exec sp_executesql @sql,N'@bl int Output ',@bl Output if(@bl>=1) begin set @b_m_return = @b_m_l_s end else begin set @b_m_return = '' end set @b=@a+1 set @a=CHARINDEX(',',@bm,@b) print @sql END ENDEND