查询结果为空结果

时间:2013-04-05 09:11:26

标签: sql

我正在尝试以下查询

`select
 skillmgt.*, competences.Competence_Description
 from skillmgt
 inner join competences
 on skillmgt.eid=competences.competence_id
 where eid=121 and datename(yyyy,timestamp)=2013`

查询成功运行,但它没有返回任何结果,尽管eid's等于某个competence_id'swhere子句也为真

实际上,即使没有where条款,它也不起作用!

编辑:通过执行以下解决方法:

 select skillmgt.*,competences.* from competences
 join skillmgt
 on competences.competence_id=skillmgt.cid
 where skillmgt.eid=121 and datename(yyyy,skillmgt.timestamp)='2013'

2 个答案:

答案 0 :(得分:2)

datename返回一个字符串。根据您的SQL风格,您应该尝试

select
 skillmgt.*, competences.Competence_Description
 from skillmgt
 inner join competences
 on skillmgt.eid=competences.competence_id
 where eid=121 and datename(yyyy,timestamp)="2013"

答案 1 :(得分:0)

试试这段代码:

select
 skillmgt.*, competences.Competence_Description
 from skillmgt,competences
where skillmgt.eid = competences.competence_id
...