A
A
Aeesha2019-11-18 07:08:54
Oracle
Aeesha, 2019-11-18 07:08:54

How to write select in PL/SQL via report variable using case?

Below is a query for a report in which you want to compare the returned data in the columns dat_prev, dat_cur. In the query, I use the variables :v_datn1,:v_datk1,:v_datn2,:v_datk2 in order to set the period.
select l.TIP, l.N_TIP, l.KOD, l.NAIM, l.ADRES, l.ZAV_NOM, l.OBJ_NAIM, f.dat,
(case when to_date(f.dat) between to_date(:v_datn1) and to_date (:v_datk1) then f.voda_k else 0 end ) dat_prev,
(case when to_date(f.dat) between to_date(:v_datn2) and to_date(:v_datk2) then f.voda_k else 0 end ) dat_cur
from rv_potreb_obj l
left join wv_nach_fino f on(l.tip=f.tip);
The problem is that case does not filter by condition, that is, what period I would not prescribe in the variables, it returns all the data for all the time to me. If you use the where condition, then how to prescribe and how then to use case in this case? I ask you to describe the various options, do not judge strictly - I am gaining experience

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-11-18
@Rsa97

Point CASE, in itself, also should not filter anything. To filter data, WHERE, HAVING and conditions in JOINs are used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question