lo solucione de esta manera
aver si alguien tiene alguna idea mejor
Código SQL
[-]
select M.Periodo, M.LIbro, M.Voucher, M.ANEXO Into #Prueba
from tblmovimientocontable M where M.AFC ='P' and
M.Periodo = :Periodo1 and M.Libro = :Libro1
Select M.Periodo, M.Libro, M.Voucher, M.Documento, P.Anexo,
SUM(Case when M.AFC = 'V' then M.n_imp else 0 end ) As Valor,
SUM(Case when M.AFC = 'I' then M.n_imp else 0 end) As IGV,
SUM(Case when M.AFC = 'N' then M.n_imp else 0 end) As NoAfecto,
SUM(case when M.AFC = 'P' then M.n_imp else 0 end ) As Total
from tblmovimientocontable M
Left Join #prueba P on M.Periodo = P.Periodo and M.Libro = P.Libro and P.Voucher = M.Voucher
where M.Periodo = :Periodo and M.Libro = :Libro
group by M.Periodo, M.Libro, M.Voucher, M.documento, P.ANEXO