/*
** add by wls For: convert many lines of SP datas to one char group by vehicle,part
*/
CREATE FUNCTION xzc.fn_getContent_SupplyPlan
(@s_p_no int = NULL,
@viewFlag varchar(1) = ''
)
RETURNS @fn_getContent_SupplyPlan TABLE
(
ID varchar(8000),
SupplyPlanNo int,
Vehicle varchar(25),
Sort varchar(20),
Part varchar(25),
RequestQty varchar(8000),
Remark varchar(255)
)
AS
BEGIN
DECLARE @sVehicle varchar(25), @sSort varchar(20)
DECLARE @sPart varchar(25), @iVehicle varchar(25)
DECLARE @iPart varchar(25), @sRemark varchar(255)
DECLARE @RequestQty int , @theID int
DECLARE @AllRequestQty varchar(8000), @allID varchar(8000)
select @AllRequestQty = ''
select @allID = ''
/*Outer CURSOR*/
DECLARE getVehiclePartSP CURSOR SCROLL FOR
select distinct Vehicle, Sort, Part from SupplyPlan
where SupplyPlanNo = @s_p_no and ViewFlag = @viewFlag
/* --Order by ID desc
select Vehicle, Sort, Part from (select min(ID) as ID, Vehicle, Sort, Part from SupplyPlan
where SupplyPlanNo = @s_p_no group by Vehicle, Sort, Part) a order by a.ID desc
*/
/*Inner CURSOR*/
DECLARE getContentSP CURSOR SCROLL FOR
select ID, Vehicle, Part, RequestQty
from SupplyPlan where SupplyPlanNo = @s_p_no and ViewFlag = @viewFlag order by ID
if @s_p_no IS NULL or @s_p_no = ''
begin
RETURN
end
OPEN getVehiclePartSP
FETCH first from getVehiclePartSP into @sVehicle,@sSort,@sPart
while(@@fetch_status = 0)
BEGIN
OPEN getContentSP
FETCH first from getContentSP into @theID, @iVehicle, @iPart, @RequestQty
while(@@fetch_status = 0)
BEGIN
if @iVehicle = @sVehicle and @iPart = @sPart
begin
select @allID = @allID + '|' + convert(varchar(15), @theID)
select @AllRequestQty = @AllRequestQty + '|' + convert(varchar(25), @RequestQty)
end
FETCH next from getContentSP into @theID, @iVehicle, @iPart, @RequestQty
END
CLOSE getContentSP
select @allID = xzc.trim_char(@allID, '|')
select @AllRequestQty = xzc.trim_char(@AllRequestQty, '|')
select @sRemark = (select top 1 Remark from SupplyPlan where SupplyPlanNo = @s_p_no
and Vehicle = @sVehicle and Part = @sPart)
INSERT INTO @fn_getContent_SupplyPlan VALUES(@allID, @s_p_no, @sVehicle, @sSort, @sPart, @AllRequestQty, @sRemark)
select @AllRequestQty = ''
select @allID = ''
select @sRemark = ''
FETCH next from getVehiclePartSP into @sVehicle,@sSort,@sPart
END
DEALLOCATE getContentSP
CLOSE getVehiclePartSP
DEALLOCATE getVehiclePartSP
RETURN
END
版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明!