如何根据用户需要进行选择语句搜索? [英] how to make a select statment to search according to user needed ?

查看:83
本文介绍了如何根据用户需要进行选择语句搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张桌子::

*第一名申请人::
(编号,名称)
* 2nd- Interview_Schedule ::
(work_flow_id,受访区,Job_ID,app_id)

*关系::

(Interview_Schedule INNER JOIN申请者在Interview_Schedule.app_id = APPS.id)上

*网络表格::

我有3个下拉列表可输入
(work_flow_id)和(interview_district)和(Job_ID)
但用户也只能输入三个参数之一
或两个,因此不需要输入三个值

#注意::

如果用户必须输入三个值,则这是选择语句.

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



#我需要::

如何进行选择陈述来搜索申请人.姓名
根据用户需要? where条件????



# I NEED ::

how to make a select statment to search for applicants.name
according to user needed ? the where condition ????

推荐答案

用户也只能输入三个参数之一或两个,因此不需要输入三个值
此UI设计只是建议这些值不是唯一链接的,如果选择搜索条件,则可以得到一个或多个结果.

在这种情况下,您需要:
1.用LIKE而不是"="更改查询.
2.在将搜索条件值分配给查询参数之前,请确保在其后加上%".
因此,如果您给"Work_Flow_ID" = 3,则将@workflowid =%3%";
=>如果您没有为JOB_ID选择任何内容,那么它将通过@ jobid ="%%";

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= "%%";

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.


这篇关于如何根据用户需要进行选择语句搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆