有一存储过程,参数如下
_Action_CardQuery
         @UserID int,
@QueryType tinyint,
@CardTYpe nvarchar(128),
@GetType int,
@BackValue int,
@Remainder int,
@D_Start nvarchar(64),
@D_End nvarchar(64),
@Code int out
我把这个存储过程的执行条件存放再数据库中
_Action_CardQuery @UserID,0,'''f35'',''f32'',''f33''' ,0,1,0,'2005-04-17','2007-04-30',@Code out
其中@CardTYpe里面的参数是带''的字符串
就是说我在这个存储过程里面执行的是 'where Type in (' +  @CardTYpe + ')'执行查询语句的。
其中'f35','f32','f33'就是传来的@CardTYpe
请问:
我在数据库中存放的_Action_CardQuery @UserID,0,'''f35'',''f32'',''f33''' ,0,1,0,'2005-04-17','2007-04-30',@Code out应该怎么拼?
我彻底拼晕啦

解决方案 »

  1.   

    declare @BagsID nvarchar(512);
    declare @Code int;
    exec _Action_CardQuery          1,0,'f35' ,0,1,0,'2005-04-17','2007-04-30',@Code out就是我执行这个,本来应该能取出值的
    但是,执行下面这个就不行。
    declare @BagsID nvarchar(512);
    declare @Code int;
    exec _Action_CardQuery          1,0,'''f35'',''f31''' ,0,1,0,'2005-04-17','2007-04-30',@Code out
    我的参数应该怎么拼?请教大家下
      

  2.   

    --如何将exec执行结果放入变量中? declare @num int, 
                   @sqls nvarchar(4000) 
    set @sqls='select @a=count(*) from tableName ' 
    exec sp_executesql @sqls,N'@a int output',@num output 
    select @num 
    --------------------------------------------------------------------------------动态sql语句基本语法 
    1 :普通SQL语句可以用Exec执行 eg:   Select * from tableName 
             Exec('select * from tableName') 
             Exec sp_executesql N'select * from tableName'    -- 请注意字符串前一定要加N 2:字段名,表名,数据库名之类作为变量时,必须用动态SQL eg:   
    declare @fname varchar(20) 
    set @fname = 'FiledName' 
    Select @fname from tableName              -- 错误,不会提示错误,但结果为固定值FiledName,并非所要。 
    Exec('select ' + @fname + ' from tableName')     -- 请注意 加号前后的 单引号的边上加空格 当然将字符串改成变量的形式也可 
    declare @fname varchar(20) 
    set @fname = 'FiledName' --设置字段名 declare @s varchar(1000) 
    set @s = 'select ' + @fname + ' from tableName' 
    Exec(@s)                -- 成功 
    exec sp_executesql @s   -- 此句会报错 declare @s Nvarchar(1000)  -- 注意此处改为nvarchar(1000) 
    set @s = 'select ' + @fname + ' from tableName' 
    Exec(@s)                -- 成功     
    exec sp_executesql @s   -- 此句正确 3. 输出参数 
    declare @num int, 
            @sqls nvarchar(4000) 
    set @sqls='select count(*) from tableName' 
    exec(@sqls) 
    --如何将exec执行结果放入变量中? declare @num int, 
                   @sqls nvarchar(4000) 
    set @sqls='select @a=count(*) from tableName ' 
    exec sp_executesql @sqls,N'@a int output',@num output 
    select @num 
      

  3.   

    呵呵,现在不是我存储过程的问题,而是我传参数的问题
    就是我不知道怎么拼凑出
    就是我的@CardType传进去的参数字符串应该是什么样的?
    Type in ('f31','f32')
    拼成动态执行的'Type in (' + @CardType + ')'
      

  4.   

    举个例子:
    create proc test_f @i int,@a int output
    as
    select @a=count(1) from ta where id=@i
    select @a
      

  5.   


    declare @a int
    exec test_f 1,@a output
      

  6.   

    'where Type in (' +  @CardTYpe + ')'
    改用CharIndex來判斷
    'where CharIndex(Type, ''' + @CardTYpe + ''') > 0'傳入參數這麼寫
    _Action_CardQuery @UserID,0,'f35,f32,f33' ,0,1,0,'2005-04-17','2007-04-30',@Code out
      

  7.   

    就是说我在这个存储过程里面执行的是 'where Type in (' +  @CardTYpe + ')'执行查询语句的。在过程中' where type in(''' + @CardTYpe + ''')' 这样不行吗?
    然后传入的参数普通形式就行了吧? 'f35'...