select f.Name as zuzhi,e.Payer_ShortName,e.ItemInfo_ItemCode,e.ItemInfo_ItemName,
e.ConfirmDate, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine
a left join SHCL..CBO_Wh b on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id
union all
(select b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate,
sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b on a.ID = b.Receivement
where 1=1 and b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001009083011046',
'1001009083021985','1001009083032924',
'1001009083043863','1001104019985903',
'1001104030207404','1001104031023415',
'1001104031328919','1001104270500855','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate )e
left join SHCL..Base_Organization_Trl f on e.CurrentOrg = f.ID
where 1=1
e.ConfirmDate, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine
a left join SHCL..CBO_Wh b on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id
union all
(select b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate,
sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b on a.ID = b.Receivement
where 1=1 and b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001009083011046',
'1001009083021985','1001009083032924',
'1001009083043863','1001104019985903',
'1001104030207404','1001104031023415',
'1001104031328919','1001104270500855','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate )e
left join SHCL..Base_Organization_Trl f on e.CurrentOrg = f.ID
where 1=1
e.ConfirmDate, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine
a left join SHCL..CBO_Wh b on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id
union all
select b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate,
sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b on a.ID = b.Receivement
where 1=1 and b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001009083011046',
'1001009083021985','1001009083032924',
'1001009083043863','1001104019985903',
'1001104030207404','1001104031023415',
'1001104031328919','1001104270500855','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate
e.ConfirmDate, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine
a left join SHCL..CBO_Wh b on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id
union all
select e.* from --这里加个select
(select b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate,
sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b on a.ID = b.Receivement
where 1=1 and b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001009083011046',
'1001009083021985','1001009083032924',
'1001009083043863','1001104019985903',
'1001104030207404','1001104031023415',
'1001104031328919','1001104270500855','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,
b.ConfirmDate )e
left join SHCL..Base_Organization_Trl f on e.CurrentOrg = f.ID
where 1=1
select e.* from select (select b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName, b.ConfirmDate, sum(b.ArriveQtySU) as sssl from PM_Receivement a left join PM_RcvLine b on a.ID = b.Receivement where 1=1 and b.ConfirmDate < '2011-7-1' and a.RcvDocType in('1001009083000107','1001009083011046', '1001009083021985','1001009083032924', '1001009083043863','1001104019985903', '1001104030207404','1001104031023415', '1001104031328919','1001104270500855','1001104304982988') group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName, b.ConfirmDate )e left join SHCL..Base_Organization_Trl f on e.CurrentOrg = f.ID where 1=1
select
f.Name as zuzhi
,e.Payer_ShortName
,e.ItemInfo_ItemCode
,e.ItemInfo_ItemName
, e.ConfirmDate
, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine a
left join SHCL..CBO_Wh b
on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c
on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id union all select
e.*
from (
select
b.CurrentOrg
,b.Payer_ShortName
,b.ItemInfo_ItemCode
,b.ItemInfo_ItemName
, b.ConfirmDate
, sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b
on a.ID = b.Receivement
where 1=1 and
b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName, b.ConfirmDate
)e
left join SHCL..Base_Organization_Trl f
on e.CurrentOrg = f.ID
where 1=1
f.Name as zuzhi
,e.Payer_ShortName
,e.ItemInfo_ItemCode
,e.ItemInfo_ItemName
, e.ConfirmDate
, isnull(sum(SUQty),0) as qc
from InvDoc_WhInitLine a
left join SHCL..CBO_Wh b
on a.Wh = b.ID
left join SHCL..CBO_Wh_Trl c
on b.ID=c.ID
group by a.Org,a.ItemInfo_ItemID,a.ItemInfo_ItemGrade,c.id union all select
e.*
from (
select
b.CurrentOrg
,b.Payer_ShortName
,b.ItemInfo_ItemCode
,b.ItemInfo_ItemName
, b.ConfirmDate
, sum(b.ArriveQtySU) as sssl
from PM_Receivement a
left join PM_RcvLine b
on a.ID = b.Receivement
where 1=1 and
b.ConfirmDate < '2011-7-1' and
a.RcvDocType in('1001009083000107','1001104304982988')
group by b.CurrentOrg,b.Payer_ShortName,b.ItemInfo_ItemCode,b.ItemInfo_ItemName, b.ConfirmDate
)e
left join SHCL..Base_Organization_Trl f
on e.CurrentOrg = f.ID
where 1=1