--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 

解决方案 »

  1.   

    --如果通過存儲過程返回則
    --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
      

  2.   

    这个问题有点simple 蹭分~~
      

  3.   

    杰伦:提示错误,过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
      

  4.   

    漏了个n,我用了varchar所以错了,谢谢,结贴
      

  5.   

    if object_id('tb')is not null drop table tb
    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*/