标题:SQL SERVER 存储过程
取消只看楼主
遗忘的爱
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2010-7-14
结帖率:50%
 问题点数:0 回复次数:1 
SQL SERVER 存储过程
程序代码:
DECLARE @sql VARCHAR(1000)
SET @sql='SELECT Item_id as '+'周数'
select @sql=@sql+
',max(case [sd] when '''+sd+''' then jhccl else 0 end)['+sd+']'
from(select distinct sd from MRP_Plan where sd<>'当前') as a
SET @sql=@sql+'from MRP_Plan  WHERE Item_id in (select distinct Item_id from MRP_Plan where Item_id in
(select Item_id from Production where work_cen_name=''中心1''))and MRP_ID=''MR002'' group  by Item_id  '
exec(@sql)
有没有办法把上面的代码改成通用的存储过程 work_cen_name和MRP_id作为输入参数?
搜索更多相关主题的帖子: 存储 
2013-01-18 10:21
遗忘的爱
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2010-7-14
得分:0 
程序代码:
Create procedure [dbo].[Work_MRP]
@id varchar(20),@name varchar(20)
as
DECLARE @@sql VARCHAR(1000)
SET @@sql='SELECT Item_id as '+'周数'select @@sql=@@sql+',max(case [sd] when '''+sd+''' then jhccl else 0 end)['+sd+']'
from(select distinct sd from MRP_Plan where sd<>'当前') as a
SET @@sql=@@sql+'from MRP_Plan  where Item_id in (select distinct Item_id from MRP_Plan where Item_id in
(select Item_id from Production where work_cen_name='''+@name+'''))and MRP_id='''+@id+''' group  by Item_id  '
exec (@@sql)
go
2013-01-18 11:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-396967-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050682 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved