0

I have a table "pupils" consisting of the following coloumns:

int      IDpupil
varchar  name
int      class

where class is a foreign key and not nullable, i.e. every pupil has to be in a class.

I'd like to see all pupils in a class depending on a class number I want to specify each time new.

The following statement does the intended if I specify a class:

SELECT "IDpupil", 
       "name", 
       "class" 
  FROM "pupils" 
 WHERE (("class" = :qClass) 
        OR (:qClass is null))

But if I want to see all pupils in that table and therefore do not specify a number it returns only the pupils of class "0". If I do this with names it works. It seems to me a null parameter gets cast to 0, what I don't want. How can I fix this?

I tried to use a case statement, which should test wether the input is Null or "", but I didn't get it to work. Maybe also for the complexity of a case statement. Then I tried this link from here. Didn't help either.

Community
  • 1
  • 1
Sebastian
  • 754
  • 4
  • 7
  • 20

1 Answers1

0

i cant see where exactely is your probleme but if you want to desplay all puils just a big select wihtout any WHERE close

SELECT "IDpupil", 
       "name", 
       "class" 
  FROM "pupils" 
mugiwaradz
  • 393
  • 1
  • 3
  • 15