--TRY
create proc text
(
@Condic varchar(200)
)
as
declare @counter int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from table where '+@Condic
exec sp_executesql @sqls,N'@a int output',@counter output
create proc text
(
@Condic varchar(200)
)
as
declare @counter int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from table where '+@Condic
exec sp_executesql @sqls,N'@a int output',@counter output
--TRY
create proc text
(
@Condic varchar(200),
@num int output
)
as
declare @counter int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from table where '+@Condic
exec sp_executesql @sqls,N'@a int output',@counter output
set @num=@counter
go
create table tb(ID int )
insert tb select 1 union all
select 2 union all
select 3 union all
select 4
if object_id('pro_test')is not null drop proc pro_test
go
create proc pro_test
(
@Condic varchar(200),
@num int output
)
as
declare @counter int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from tb where '+@Condic
exec sp_executesql @sqls,N'@a int output',@counter output
set @num=@counter
go
declare @num int
exec pro_test ' id>1',@num output
select @num
/*-----------
3*/