2

i have these sql statement to output job field based on user input.

    SELECT jf.name, j.jname, c.cname, cj.url
    FROM company_has_job cj
        INNER JOIN job j ON j.id = cj.job_id
        INNER JOIN company c ON c.id = cj.company_id
        INNER JOIN jobfield_has_job jhj ON jhj.job_id = j.id
        INNER JOIN jobfield jf ON jf.id = jhj.jobfield_id
    WHERE jf.name LIKE '%' + @InputJob + '%'

for example when user input query "Programmer", the system will output all programmer job defined in the database.but the system does not show any result if i enter "Program" in the search box. This is my control parameter:

<SelectParameters>
    <asp:ControlParameter ControlID="TextBox4" Name="InputExpertise" 
        PropertyName="Text"/>
</SelectParameters>

can you tell me where i did wrong? your help is much appreciated.

4

2 回答 2

3

我不确定这是否只是一个错字,但不应该是

WHERE jf.name LIKE '''%' + @InputJob + '%'''

请注意,我这样做是为了使代码最终以 . 结尾LIKE '%Program%',而看起来它将以LIKE %Program%当前结尾。

于 2012-06-20T17:22:21.527 回答
1

还不能发表评论,但也许这会回答这个问题,您加入的任何列是否允许 NULL?内连接不会返回包含空值的结果。

考虑这个查询:

select wb.employee,wb.Dept from web_user wb
inner join Employee e on wb.Dept = e.Department
where wb.employee like '%Ted%'

没有结果

但是这个:

select wb.employee,wb.Dept from web_user wb
left join Employee e on wb.Dept = e.Department
where wb.employee like '%Ted%'

返回: 泰德 NULL

此外,它对调试很有帮助,在对数据库的实际调用中设置断点以获取它正在使用的 SQL 语句,然后将其粘贴到查询编辑器中。当查询不正常时,我已经多次这样做了。一旦您知道程序对 SQL 语句使用什么,这也可以帮助您找到问题。

于 2012-06-20T20:15:16.647 回答