ALTER PROCEDURE [dbo].[K_RT_GetWareHousedailyReport]
@fromdate datetime,
@todate datetime,
@branch varchar(50)
AS
BEGIN
SET NOCOUNT ON;
select
MR.Branch, convert(varchar(50), WH.date, 103) as Date,
WH.NoofBirds, WH.Weight, WH.Meatyield,
max(case when BT.birdname='Bone Less' then WHT.weight end) as BoneLess,
max(case when BT.birdname='Skin Less' then WHT.weight end) as SkinLess,
max(case when BT.birdname='Wings' then WHT.weight end) as Wings,
max(case when BT.birdname='Liver' then WHT.weight end) as Liver
from
K_RT_WarehouseDetails WH
inner join
K_RT_WarehouseTypeWeight WHT on WH.sno = WHT.ID
inner join
K_RT_MasterRetailStores MR on MR.sno = WH.branch
inner join
K_RT_BirdType BT on BT.sno = WHT.[type]
where
MR.sno = @branch
and WH.date between @fromdate And @todate
group by
BT.birdname, WHT.weight, MR.branch, date, WH.noofbirds, WH.weight, WH.meatyield, WHT.ID
order by
WHT.ID
END
此查询返回四行中的每一行输出,但我只希望在一行中是否可能?我为数据透视表编写了这个程序。请告诉我任何一个。
答案 0 :(得分:2)
您不应按BT.birdname
和WHT.weight
....
group by MR.branch,date,WH.noofbirds,WH.weight,WH.meatyield,
WHT.ID
order by WHT.ID