Raphael Gomes Posted January 25 Topic Count: 10 Topics Per Day: 0.01 Content Count: 38 Content Per Day: 0.05 Reputation: 4 Achievement Points: 261 Solved Content: 0 Days Won: 0 Status: Offline Device: Windows Report Share Posted January 25 Bom dia, Estou com a missão de realizar uma query que busca Orçado x Realizado x Saldo conforme a tarefa do projeto e período: A questão é, existe alguma tabela de histórico de orçamento? Como está a consulta hoje: select mtarefa.idprj [identificador do projeto], mtarefa.codtrf [código da tarefa], mtarefa.descricao [descrição da tarefa], mtarefa.idpai, format(isnull(mtarefa.custototal, 0), 'n', 'pt-br') as 'orçado', format(isnull((select sum(titmmovratccu.valor) from titmmovratccu left join titmmov on titmmovratccu.codcoligada = titmmov.codcoligada and titmmovratccu.idmov = titmmov.idmov and titmmovratccu.nseqitmmov = titmmov.nseqitmmov left join tmov on titmmov.codcoligada = tmov.codcoligada and titmmov.idmov = tmov.idmov where titmmovratccu.codcoligada = mtarefa.codcoligada and titmmovratccu.idprj = mtarefa.idprj and titmmovratccu.idtrf = mtarefa.idtrf and (tmov.codtmv in ('1.1.06', '1.1.28', '1.1.10', '1.1.59') or tmov.codtmv is null) and tmov.datacriacao >= '20230101' and tmov.datacriacao <= '20240125' /*and tmov.codtmv <> '1.1.08'*/), 0), 'n', 'pt-br') as 'realizado', format((isnull(mtarefa.custototal, 0) - isnull((select sum(titmmovratccu.valor) from titmmovratccu left join titmmov on titmmovratccu.codcoligada = titmmov.codcoligada and titmmovratccu.idmov = titmmov.idmov and titmmovratccu.nseqitmmov = titmmov.nseqitmmov left join tmov on titmmov.codcoligada = tmov.codcoligada and titmmov.idmov = tmov.idmov where titmmovratccu.codcoligada = mtarefa.codcoligada and titmmovratccu.idprj = mtarefa.idprj and titmmovratccu.idtrf = mtarefa.idtrf and (tmov.codtmv in ('1.1.06', '1.1.28', '1.1.10', '1.1.59') or tmov.codtmv is null) and tmov.datacriacao >= '20230101' and tmov.datacriacao <= '20240125' /*and tmov.codtmv <> '1.1.08'*/), 0)), 'n', 'pt-br') as 'saldo' from mtarefa join mtrfcompl on mtarefa.codcoligada = mtrfcompl.codcoligada and mtarefa.idprj = mtrfcompl.idprj and mtarefa.idtrf = mtrfcompl.idtrf where mtarefa.idprj = 53 and mtarefa.tipoplanilha <> 1 group by mtarefa.idprj, mtarefa.codtrf, mtarefa.descricao, mtarefa.idtrf, mtarefa.custototal, mtarefa.codcoligada Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.