robert030975
MIS
- Oct 17, 2006
- 227
HI I have a problem that I can't seem to do in one select.
fullcode gbbin qbbin pqty gbqty
N3A2020/N050/L 0 270A1 0 11
N3A2020/N050/L 253A1 0 22 0
Now the productcode and bins are varchar but what I want to see without have to create two tables and join
is have the select into one row
N3A2020/N050/L 253A1 270A1 22 11
Now I can sum both the qty's but how do I get round the bin.
FYI heres the openquery union select
Select Fullcode, gbbin, qbbin , pqty, gbqty from (
Select fullcode, '0' as gbbin, bin as qbbin, sum ( physicalqty) as pqty , 0 as gbqty from openquery ( CERP, '
SELECT
st_stbin.whse,
st_stbin.bin,
st_stbin.physicalqty,
st_stbin.allocateqty,
st_stbin.physicalqty - st_stbin.allocateqty,
st_stock.fullcode,
st_stock.descr
FROM
st_stbin,
st_stock,
jv_missstock
WHERE
( jv_missstock.stockhash=st_stock.hash )
AND ( jv_missstock.stockhash=st_stbin.stockhash )
AND
(
st_stbin.whse = ''QB01''
AND
st_stbin.bin BETWEEN ''270A1'' AND ''290A1''
AND
st_stock.fullcode[1,3] BETWEEN ''N3A'' AND ''N3A''
AND
st_stbin.physicalqty > 0
)' )
Group by fullcode, bin
UNION
Select fullcode, bin as gbbin, '0' as qbbin, 0 as pqty , sum ( physicalqty) as gbqty from openquery ( CERP, '
SELECT
st_stbin.whse,
st_stbin.bin,
st_stbin.physicalqty,
st_stbin.allocateqty,
st_stbin.physicalqty - st_stbin.allocateqty,
st_stock.fullcode,
st_stock.descr
FROM
st_stbin,
st_stock,
jv_missstock
WHERE
( jv_missstock.stockhash=st_stock.hash )
AND ( jv_missstock.stockhash=st_stbin.stockhash )
AND
(
st_stbin.whse = ''GB01''
AND
st_stock.fullcode[1,3] BETWEEN ''N3A'' AND ''N3A''
AND
st_stbin.physicalqty > 0
)' )
Group by fullcode, bin )a
Any Help whould be great!!
fullcode gbbin qbbin pqty gbqty
N3A2020/N050/L 0 270A1 0 11
N3A2020/N050/L 253A1 0 22 0
Now the productcode and bins are varchar but what I want to see without have to create two tables and join
is have the select into one row
N3A2020/N050/L 253A1 270A1 22 11
Now I can sum both the qty's but how do I get round the bin.
FYI heres the openquery union select
Select Fullcode, gbbin, qbbin , pqty, gbqty from (
Select fullcode, '0' as gbbin, bin as qbbin, sum ( physicalqty) as pqty , 0 as gbqty from openquery ( CERP, '
SELECT
st_stbin.whse,
st_stbin.bin,
st_stbin.physicalqty,
st_stbin.allocateqty,
st_stbin.physicalqty - st_stbin.allocateqty,
st_stock.fullcode,
st_stock.descr
FROM
st_stbin,
st_stock,
jv_missstock
WHERE
( jv_missstock.stockhash=st_stock.hash )
AND ( jv_missstock.stockhash=st_stbin.stockhash )
AND
(
st_stbin.whse = ''QB01''
AND
st_stbin.bin BETWEEN ''270A1'' AND ''290A1''
AND
st_stock.fullcode[1,3] BETWEEN ''N3A'' AND ''N3A''
AND
st_stbin.physicalqty > 0
)' )
Group by fullcode, bin
UNION
Select fullcode, bin as gbbin, '0' as qbbin, 0 as pqty , sum ( physicalqty) as gbqty from openquery ( CERP, '
SELECT
st_stbin.whse,
st_stbin.bin,
st_stbin.physicalqty,
st_stbin.allocateqty,
st_stbin.physicalqty - st_stbin.allocateqty,
st_stock.fullcode,
st_stock.descr
FROM
st_stbin,
st_stock,
jv_missstock
WHERE
( jv_missstock.stockhash=st_stock.hash )
AND ( jv_missstock.stockhash=st_stbin.stockhash )
AND
(
st_stbin.whse = ''GB01''
AND
st_stock.fullcode[1,3] BETWEEN ''N3A'' AND ''N3A''
AND
st_stbin.physicalqty > 0
)' )
Group by fullcode, bin )a
Any Help whould be great!!