0

I have a problem with my ORDER BY condition in data model. I want to pass a parameter to ORDER BY and sort data according to the value of parameter. This is the code:

select *
from   (
   select t1.header_id,
          t1.ebs_trx_number BROJ_FAKTURE,
          t1.premise_or_group_code OZNAKA_PROSTORA_ILI_GRUPE,
          t1.SHIP_TO_ADDRESS ADRESA_PROSTORA_ILI_GRUPE,
          to_number(t1.code_customer) SIFRA_KUPCA,
          t1.name_customer NAZIV_KUPCA,
          t1.heating_type VRSTA_GREJANJA,
          t1.amount_vat_excluded IZNOS_BEZ_PDV,
          t1.amount_vat PDV,
          t1.amount_vat_included IZNOS_SA_PDV
   from   XXBILL.XXBILL_INVOICE_HEADERS_HISTORY t1
   where  t1.billing_period = :P_PERIOD
   and    t1.heating_type = nvl(:P_HEATING_TYPE, t1.heating_type)
   UNION
   select t2.header_id,
          t2.ebs_trx_number,
          t2.premise_or_group_code,
          t2.SHIP_TO_ADDRESS,
          to_number(t2.code_customer),
          t2.name_customer,
          t2.heating_type,
          t2.amount_vat_excluded,
          t2.amount_vat,
          t2.amount_vat_included
   from   XXBILL.XXBILL_INVOICE_HEADERS t2
   where  exists (select 1
                  from   xxbill.xxbill_period t3
                  where  t3.ID_PERIOD = :P_PERIOD
                  and    t3.STATUS = 'OTV')
   and    t2.heating_type = nvl(:P_HEATING_TYPE, t2.heating_type)
   )
order  by :P_SORT

P_SORT can be either 2, 3 or 5, and BIP accepts this code but it just want sort the data.

Does anyone know how can i solve this problem?

Thanks in advance, Stefan

Stefan Dramlic
  • 69
  • 1
  • 1
  • 6

1 Answers1

2

if you want to order by the column :p_short,it should contain more than one value. To take more that one value to parameter you have to create LOV for that.if you will enter a single value for the parameter anyways order by may not work.

Hope it makes sense.

Please update if you have any other concerns too?

mona16
  • 46
  • 8