Passing parameters in a SQL query
I am passing where are the values โโof the offer parameter from the program, however, when I send at least one value, I get the result, however, if I send all the parameters as a null result, I want to get a request like this that if all the parameters are sent as null. all records in the database will be displayed
Below is a query that retrieves values โโif one condition is met
SELECT *
FROM STUDENT
LEFT JOIN COURSE
ON STUDENT.COURSE_ID = COURSE.COURSE_ID
WHERE STUDENT.STD_ID = null
OR STUDENT.STD_NAME = null
OR STUDENT.STD_START_DATE = null
OR STUDENT.STD_END_DATE = null
OR STUDENT.STD_GENDER = null
OR STUDENT.COURSE_ID = null;
+3
source to share
2 answers
The resulting solution:
SELECT *
FROM
STUDENT S,COURSE C
WHERE
S.STD_ID like '%'||null||'%' and S.STD_NAME like '%'||null ||'%' and S.STD_START_DATE like '%'||null ||'%' and S.STD_END_DATE like '%'||null ||'%' and S.STD_GENDER like '%'||null||'%'
and S.COURSE_ID like '%'||null||'%' and S.COURSE_ID=C.COURSE_ID
0
source to share