2013-04-05 11 views
0

我想下面的查詢查詢結果爲空結果

`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' 
+1

什麼SQL風味/數據庫您使用? – 2013-04-05 09:18:57

+0

@dystroy,我解決它通過改變檢索的邏輯..有點不可思議,因爲它應該從一開始...其實已經工作 非常感謝反正 – auicsc 2013-04-05 09:29:09

回答

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

,甚至當我嘗試沒有where子句中它不顯示任何行! – auicsc 2013-04-05 09:14:18

+0

然後我們可能需要更多的信息,比如表結構和應該匹配的行的例子。 – 2013-04-05 09:16:33

0

試試這個代碼:

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