Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have 2 table ::

*1st- applicants ::
(id , name)
*2nd- Interview_Schedule ::
( work_flow_id , interview_district , Job_ID , app_id)

*relation ::

(Interview_Schedule INNER JOIN applicants ON Interview_Schedule.app_id = applicants.id)

*WEBFORM ::

i have 3 dropdownlists to enter
( work_flow_id ) and (interview_district) and (Job_ID)
but the user can also enter only one of the three parameters
or two so its not required to enter the three values

# note ::

this is the select statment if the user must enter the three values

SELECT        applicants.name
FROM          Interview_Schedule INNER JOIN
              applicants ON Interview_Schedule.app_id = applicants.id
WHERE        Interview_Schedule.work_flow_id=@worflowid AND Interview_Schedule.interview_district=@distid AND Interview_Schedule.Job_ID=@jobid


# I NEED ::

how to make a select statment to search for applicants.name
according to user needed ? the where condition ????
Posted
Comments
Albin Abel 1-Mar-11 4:31am    
if one either one condition satisfy your result then why you want to check three condition. Use OR instead of AND in the where condition?

1 solution

the user can also enter only one of the three parameters or two so its not required to enter the three values
This UI design simply suggests that the values are not uniquely linked and you can get one or more results if you select the search criteria.

When, this is the case, you need to:
1. Change the query with LIKE instead of '='.
2. Make sure you put a '%' append to the search criteria values before assigning it to the parameters of query.
Thus, if you give 'Work_Flow_ID' = 3, then put @workflowid = "%3%";
=> if you select nothing for JOB_ID, then it will pass @jobid= "%%";

SQL
SELECT        
      applicants.name
FROM          
      Interview_Schedule 
INNER JOIN
      applicants ON Interview_Schedule.app_id = applicants.id
WHERE        
     Interview_Schedule.work_flow_id LIKE @worflowid 
AND 
     Interview_Schedule.interview_district LIKE @distid 
AND 
     Interview_Schedule.Job_ID LIKE @jobid


P.S.: Above changes does not ensure you a single unique record. In order to make that sure, you need to make atleast one field mandatory.
 
Share this answer
 
Comments
MohammedSabry 1-Mar-11 19:07pm    
it`s works but it didn`t give the right values !!
Sandeep Mewara 2-Mar-11 0:17am    
You surely did not read what I said. Your UI is wrong if you want a specific result.

You designed search screens will/will not give specific result at times. Further, I don't know what 'it didn't give the right values' means here.
AFAIK, this would work like a charm, unless you do some mistake or have a different requirement and result expectation.

Carry on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900