Skip to content
Advertisement

WHERE conditions in SQL (ORACLE)

People, I need a help.

I have the following code:

We have 3 parameter here: DATE, CODORDEM, GRAU. The user can enter with;

  1. ONLY the ‘date’ (without ‘GRAU’ and ‘CODORDEM’)
  2. The ‘date’ AND the ‘grau’ (without ‘CODORDEM’)
  3. The ‘date’ AND the ‘codordem’ (without ‘grau’)

Where is my mistake in the code?

My actual code does: 1 – the user can enter with date + grau + codordem 2 – the user can enter with date + grau

Advertisement

Answer

Move join condition to join clause. Add criterium for dates always. Then check if both of remaining parameters are null or only one of them and second is met.

Replace :parameter is null with to_char(:parameter) = 'X' if they are sent as Xs. As I understood situation where you provide dates and both remaining parameters is forbidden.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement