更改过程[dbo]。[SerailNo_LoadValue]
(
@SerialNo int,
@Season nchar(5)
)
AS
BEGIN
如果存在(从MATERIAL_Stock WHERE SerialNo = @SerialNo和Season = @Season中选择1)
BEGIN
if(@Season ='PER')
开始
SELECT material_code,ULC_id,setNo,MONTH(GETDATE())AS Delivery_Month,YEAR(GETDATE())AS Delivery_Year,1 AS NORECORD
,ISNULL(qty_total,0)AS qty_total,ISNULL(ULC,0)AS'ulsmtr',isnull(MATNR,'')as MATNR-由LALIT添加,与DIPENDRA讨论于2016年4月22日
从MATERIAL_Stock左加入ULC_master到ULC_master.ID = MATERIAL_Stock.ULC_id,其中SerialNo = @SerialNo和Season = @Season
END
否则
开始
SELECT material_code,ULC_id,setNo,Delivery_Month,Delivery_Year,1 AS NORECORD
,ISNULL(qty_total,0)AS qty_total,ISNULL(ULC,0)AS'ulsmtr',isnull(MATNR,'')as MATNR-由LALIT添加,与DIPENDRA讨论于2016年4月22日
从MATERIAL_Stock左加入ULC_master到ULC_master.ID = MATERIAL_Stock.ULC_id,其中SerialNo = @SerialNo和Season = @Season
END
从Material_stock中选择不同的Delivery_Year,Delivery_Month,Season到#T 其中Season = @ Season 按Delivery_Year,Delivery_Month排序
选择*,ROW_NUMBER()超过(按Delivery_Year,Delivery_Month排序)AS行号从#T到#TT
声明@MONTH int 声明@YEAR int 声明@ROWID int 从dbo.Material_stock中选择前1个@ MONTH = Delivery_Month,@ YEAR = Delivery_Year,其中Season = @ Season And SerialNo = @ SerialNo 从#TT中选择@ ROWID = RowNumber,其中Delivery_Month = @ MONTH和Delivery_Year = @ YEAR 从#TT中选择Delivery_Year作为Delivery_Month1,Delivery_Month,Delivery_Year,Season,RowNumber,其中RowNumber> = @ ROWID
放置表#T 放置表#TT
END
END