首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程的改法

2012-03-01 
求一个存储过程的改法CREATEprocxxxx(@companynameintnull--这里不知道要如何改,改成什么类型的)asbegins

求一个存储过程的改法
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。行不行?

热点排行