1
I have the following queries, Q1:
SELECT finempe.codigo_orgao
,finempe.cod_reduzido
,finempe.num_empenho
,finempe.data_empenho
,finempe.nome_fornecedor
,finempe.valor_empenhado
,finempe.valor_anulado
,finempe.valor_pago
,finempe.valor_liquidado
,cast(finempe.valor_empenhado as decimal(18,2)) - cast(finempe.valor_anulado as decimal(18,2)) - cast(finempe.valor_liquidado as decimal(18,2)) as sld_a_liquidar
,cast(finempe.valor_empenhado as decimal(18,2)) - cast(finempe.valor_anulado as decimal(18,2)) - cast(finempe.valor_pago as decimal(18,2)) as sld_a_pagar
FROM [Cont98].[dbo].[finempe]
where finempe.codigo_orgao = 01 and finempe.data_empenho between '01-01-1998' and '31-12-1998'
order by finempe.cod_reduzido, finempe.num_empenho
and, Q2:
SELECT cod_reduzido
,sld_orc_ano
,sld_supl_ano
,sld_esp_ano
,sld_ext_ano
,sld_re_ano
,orcplade.descricao
FROM Cont98.dbo.orcdotac
inner join orcplade on
(orcdotac.conta_desp = orcplade.conta_desp)
WHERE codigo_orgao = 01 and cod_reduzido != 0
ORDER BY cod_reduzido
I would like to combine them as follows: to each cod_reduzido
of Q2 will have n tuples of Q1 (who possess the same cod_reduzido
), how could I solve this problem of mine?
You need the table of Q1 (
finempe
) relates to any of the tables of Q2 (orcdotac
ororcplade
). Is there a field that does that? Likefinempe.id_orcdotac
– rLinhares
@rLinhares dude, there is no field that does this, at most cod_reduced is equal for both, but these two tables belong to the same BD
– V.Avancini
That’s why
cod_reduzido
that you know that an occurrence of Q1 relates to x occurrences of Q2? If so, this guy will be used. (if yes, in which of the two tables of Q2 it is?)– rLinhares
As for what you said about "these two tables belong to the same BD", it doesn’t mean they have relation; for example I can have the table
usuarios
and thecores_produto
that do not relate to anything. Understand?!– rLinhares
it is in both tables, both in Q1 and Q2, I will display in an html table, where Q2 would be like a title and Q1 the tuples with the information, but it has N titles and N information.
– V.Avancini
@rLinhares , I understand... so basically they have no relationship, but at the same time it has, like a paradox same
– V.Avancini