Good afternoon guys
I have a code here that returns me two lines. Equal partly
One is outflow of stock and another return.
I asked for 30 products. And I returned 15. In my I need only the total of those who left.
ie only 15. As I could do this. I have no idea how
I await replies
How to make calculations, with conditions
-
- Rank: Estagiário Sênior
- Posts: 12
- Joined: Tue, 19 Apr 2011 10:24 am
- Location: São paulo - SP
JImmy
Let me see if I understand
You asked for 30 products and returned 15. You want the total of that no returned, that in the case is 15?
You asked for 30 products and returned 15. You want the total of that no returned, that in the case is 15?
-
- Rank: DBA Pleno
- Posts: 297
- Joined: Tue, 21 Dec 2010 8:45 am
- Location: Florianopolis
Priscila Fernandes
Exactly this
an example of my code
an example of my code
(select me.nr_solicitacao, me.dt_movto, me.cd_estado, me.tp_movto, me.qt_movto
from movto_est_medicamento me
where me.cd_estado
and me.dt_movto between '14/07/2011' and '14/07/2011')
-
- Rank: Estagiário Sênior
- Posts: 12
- Joined: Tue, 19 Apr 2011 10:24 am
- Location: São paulo - SP
JImmy
Some of these fields serves as a parameter to know what came out and what returned? Ex. What returned records with a 'R'.
In this select, the range '14 / 07/2011 '- '14 / 07/2011' is the products that left?
In this select, the range '14 / 07/2011 '- '14 / 07/2011' is the products that left?
-
- Rank: DBA Pleno
- Posts: 297
- Joined: Tue, 21 Dec 2010 8:45 am
- Location: Florianopolis
Priscila Fernandes
No. He brings everything.
All that left. But it makes a copy of what was returned também. When I return it does not update and yes it creates another line.
This date should bring all producer who were provided.
That is,
returned 15, should return 15.
They left 30
I do not know if he could understand
All that left. But it makes a copy of what was returned também. When I return it does not update and yes it creates another line.
This date should bring all producer who were provided.
That is,
returned 15, should return 15.
They left 30
I do not know if he could understand
-
- Rank: Estagiário Sênior
- Posts: 12
- Joined: Tue, 19 Apr 2011 10:24 am
- Location: São paulo - SP
JImmy
So let me see if this example fits
in the range '14/07 / 2011 '- '14 / 07/2011' You asked to list all the products that left, right? In total, 15 products left. In Select, you should return 15. However, when you register the return, it writes another line. So, instead of returning 15, returns 30. Is that pri?
in the range '14/07 / 2011 '- '14 / 07/2011' You asked to list all the products that left, right? In total, 15 products left. In Select, you should return 15. However, when you register the return, it writes another line. So, instead of returning 15, returns 30. Is that pri?
-
- Rank: DBA Pleno
- Posts: 297
- Joined: Tue, 21 Dec 2010 8:45 am
- Location: Florianopolis
Priscila Fernandes
Someone can help me there
I was able to do
does what I want. But you do not return anything when you only have S.
Someone can give me a light.; ....
I was able to do
sum(decode(m.tp_movto,'S',m.qt_servico)) - sum(decode(m.tp_movto,'R',m.qt_servico))
Someone can give me a light.; ....
-
- Rank: Programador Sênior
- Posts: 45
- Joined: Thu, 12 May 2011 4:54 pm
- Location: Porto Alegre - RS
Hehehehe
What a sculptive ....
Priscilla could barely explain your problem.
The main question here is: How do you know that a product returned? Is there a field that tells you this? What table is that you can consulting?
What a sculptive ....
Priscilla could barely explain your problem.
The main question here is: How do you know that a product returned? Is there a field that tells you this? What table is that you can consulting?
-
- Rank: Programador Sênior
- Posts: 45
- Joined: Thu, 12 May 2011 4:54 pm
- Location: Porto Alegre - RS
So, you should watch the records in a traffic history table, right?When I make return it does not update and yes it creates another line
Each time you enter or leave products, you register what was bustling, right?
Type Thus:
cod_prod nome_prod qt_movimentada dt_movimentada tp_movimento
123 produto ABC 30 14/07/2011 Saida
123 produto ABC 15 14/07/2001 Retorno
From then on, you need to read the records and deduce that you have 15 products that have not returned, right?
-
- Rank: Programador Sênior
- Posts: 45
- Joined: Thu, 12 May 2011 4:54 pm
- Location: Porto Alegre - RS
So, follow the way you're going that's right.
uses Sum (Decode (....)) as you are using, and then boot a group by in the main fields: cod_product, name_pring, dt_mement, etc.
] This should work. Otherwise, it warns.
uses Sum (Decode (....)) as you are using, and then boot a group by in the main fields: cod_product, name_pring, dt_mement, etc.
] This should work. Otherwise, it warns.
-
- Rank: DBA Pleno
- Posts: 297
- Joined: Tue, 21 Dec 2010 8:45 am
- Location: Florianopolis
Priscila Fernandes
Dae Marcus
Looks OS
It did not work
He still returns the two normal lines. The result of Sum da. Exit 20 and then return -15. Where the result should be 5
Looks OS
It did not work
select sum(decode(m.tp_movto,'S',m.qt_servico,0)) - sum(decode(m.tp_movto,'R',m.qt_servico,0))testesa, m.dt_movto, m.nr_solicitacao, pj.nm_entidade,
s.ds_servico, m.qt_servico, m.dt_validade,
m.cd_lote, pfabr.nm_fantasia, m.fg_ddu
from solicitacao_medicamento sm,
movto_est_medicamento m,
item_solicitacao_medicamento i,
pessoa_juridica pj,
servicos s,
pessoa_juridica pfabr
where m.dt_movto between '14/07/2011' and '14/07/2011'
and sm.nr_solicitacao = m.nr_solicitacao
and sm.nr_solicitacao = i.nr_solicitacao
and i.cd_servico = m.cd_servico
and sm.cd_entidade_solicitacao = pj.id_pessoajuridica
and i.cd_servico = s.cd_servico
and m.cd_fabricante = pfabr.id_pessoajuridica(+)
group by m.cd_lote,m.dt_movto, m.nr_solicitacao, pj.nm_entidade,
s.ds_servico, m.qt_servico, m.dt_validade,
pfabr.nm_fantasia, m.fg_ddu
-
- Rank: DBA Sênior
- Posts: 389
- Joined: Tue, 27 Jul 2010 1:34 pm
- Location: Sapiranga - RS
- Contact:
Quem falou que programar era fácil??
Quanto mais dificil for a implementação mais valorizado seu trabalho será!
Acessem: www.gfkauer.com.br
Quanto mais dificil for a implementação mais valorizado seu trabalho será!
Acessem: www.gfkauer.com.br
The problem is as follows, you have a cluster by the service, considering that there are 2 different services, a output and a return, can not group this way.
The solution is to rewrite the entire consultation. I'll see if I set an example for you.
The solution is to rewrite the entire consultation. I'll see if I set an example for you.
-
- Rank: DBA Pleno
- Posts: 232
- Joined: Fri, 30 Mar 2007 7:26 pm
- Location: Londrina - PR
Rafael O. Genaro
Some information is missing.
- How to identify which request refers to the return? Is the 'r' movement always generated with the same output request number?
- Can there be more than one return to the same exit?
- The date of the return movement can be different from the output date? If so, should you consider the date of the return movement?
For example:
Day 01 An outlet of 10 units is generated.
Day 02 The return of 02 units is generated.
Day 03 The return of 08 units is generated.
Generating the report on 01 to day 02, should return 08 units? Or should you consider the movement of the 03 too, returning 0?
Considering that the request number is the way to group the output and return records, and which should be considered only the limited movements at the interval of the dates informed as a parameter:
- How to identify which request refers to the return? Is the 'r' movement always generated with the same output request number?
- Can there be more than one return to the same exit?
- The date of the return movement can be different from the output date? If so, should you consider the date of the return movement?
For example:
Day 01 An outlet of 10 units is generated.
Day 02 The return of 02 units is generated.
Day 03 The return of 08 units is generated.
Generating the report on 01 to day 02, should return 08 units? Or should you consider the movement of the 03 too, returning 0?
Considering that the request number is the way to group the output and return records, and which should be considered only the limited movements at the interval of the dates informed as a parameter:
select *
from
(
select sum( decode( tp_movto, 'S', 1, 'R', -1, 0 ) * qt_servico ) over ( partition by nr_solicitacao ) qt_movimentada
, dt_movto
, nr_solicitacao
, nm_entidade
, tp_movto
from
(
-- Apenas para simular alguns registros
select 20 qt_servico
, to_date('14/07/2011', 'dd/mm/yyyy') dt_movto
, 3 nr_solicitacao
, 'HOSPITAL LIOFILIZADO FATOR VIII - 250 UI' nm_entidade
, 'S' tp_movto
from dual
union all
select 5 qt_servico
, to_date('14/07/2011', 'dd/mm/yyyy') dt_movto
, 3 nr_solicitacao
, 'HOSPITAL LIOFILIZADO FATOR VIII - 250 UI' nm_entidade
, 'R' tp_movto
from dual
union all
select 2 qt_servico
, to_date('17/07/2011', 'dd/mm/yyyy') dt_movto
, 3 nr_solicitacao
, 'HOSPITAL LIOFILIZADO FATOR VIII - 250 UI' nm_entidade
, 'R' tp_movto
from dual
union all
select 10 qt_servico
, to_date('15/07/2011', 'dd/mm/yyyy') dt_movto
, 4 nr_solicitacao
, 'TESTE' nm_entidade
, 'S' tp_movto
from dual
--
) a
where dt_movto between to_date('14/07/2011', 'dd/mm/yyyy') and to_date('19/07/2011', 'dd/mm/yyyy')
) a
where a.tp_movto = 'S'
and a.qt_movimentada >= 0 -- Se houver retorno de todos os itens movimentados, exibir a linha?
-- E se a quantidade retornada for maior do que a quantidade registrada na saída?
-
- Information
-
Who is online
Users browsing this forum: No registered users and 16 guests