select A.cpbh, A.kcsl yckc,
(select sum(sl) from mxb where cpbh = A.cpbh and flag = '入库' adn month(日期) = month(getdate())) byck,
(select sum(sl) from mxb where cpbh = A.cpbh and flag = '出库' adn month(日期) = month(getdate())) byrk
into yourtable
from kcb A
where month(日期) = month(getdate())-1