日期:2014-05-18  浏览次数:20401 次

求一个存储过程的改法
CREATE   proc   xxxx
(
@companyname   int=null--这里不知道要如何改,改成什么类型的
)
as
begin

select   公司id,gsid,公司名称,sum(金额)   as   用款总额   from  
(
                                      select   *   from   a
                                      union   all
                                      select   *   from   b
)   t  
where   审批意见= '同意 '
and   gsid   in   (case   when   @companyname   is   null   then   gsid   else   @companyname   end)
group   by   公司id,gsid,公司名称   order   by   公司id

end
GO

我想实现@companyname这个输入参数可以直接支持如这样的123,56,554(数量不定,数值是gsid字段值)或是123这样单个gsid,现在不行,会报错,不知道要如何改了


------解决方案--------------------
那用字符型呀varchar(200)is null
------解决方案--------------------
拼接一个SQL语句,然后execute。行不行?