你用的时候
usp_account('(1,2,3)')可以吗?

解决方案 »

  1.   

    in 后面也跟一个select语句可以吗
      

  2.   

    是不是改成function 啊,我觉得可能用function更好
    create  function usp_account(@for_code varchar(200))
    returns table
    as
     return(Select b.material_code,sum(b.qty) as qty 
        from master a, detail b where a.for_cod=b.for_code
        and A.for_code in (@For_code))
      

  3.   

    是不是改成function 啊,我觉得可能用function更好
    create  function usp_account(@for_code varchar(200))
    returns table
    as
     return(Select b.material_code,sum(b.qty) as qty 
        from master a, detail b where a.for_cod=b.for_code
        and A.for_code in (@For_code))
      

  4.   

    usp_account (['a','b','c'])不行吗?
      

  5.   

    同意linqiang_46(林强)
        Select b.material_code,sum(b.qty) as qty 
        from master a, detail b where a.for_cod=b.for_code
        and A.for_code in (SELECT FIELDNAME FROM TABLE WHERE
        FIELDNAME=@For_code)
    如果不能从数据库中取,就多用几个参数。
      

  6.   

    如果你的集合很多的话,可以多定义几个参数
    Create procedre usp_account @for_code varchar(200)
    as
    begin
        Select b.material_code,sum(b.qty) as qty 
        from master a, detail b where a.for_cod=b.for_code
        and A.for_code in (@For_code)
        Group By b.material
    end
      

  7.   

    可以这样做啊
    Create procedre usp_account @for_code varchar(200)
    as
    begin
      declare @str varchar(500)
      select @str='Select b.material_code,sum(b.qty) as qty 
        from master a, detail b where a.for_cod=b.for_code
        and A.for_code in ('+@For_code+')'
      exec(@str)
    end