2014-03-07 37 views
0

我有2個表,每列有MNR。我想加入他們與這個專欄。SQL語法或數據庫限制?

以下兩條SQL語句失敗。最後一個顯示我的日期格式正在工作(改變會話格式)。 DB是Oracle。

有人可以告訴我我做錯了什麼嗎?我該如何稱此連接?

// fails 
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR 
from INFOR.RELFBR as a, INFOR.RELXDB as b 
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10') 
    and (a.CREATEDATE >= '01.01.2014 00:00:00') 
order by a.CREATEDATE 

// fails as well 
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR 
from INFOR.RELFBR as a, INFOR.RELXDB as b 
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10') 
order by a.CREATEDATE 

// all fine 
select CREATEDATE, MNR 
from INFOR.RELFBR 
where (CREATEDATE >= '01.01.2014 00:00:00') 
order by CREATEDATE 

失敗的錯誤是ORA-00933: SQL command not properly ended
「由......爲了」 發生同樣的錯誤,取出後。

+0

是什麼錯誤消息? –

+0

失敗....有哪個錯誤? –

+0

@BobJarvis我正在使用C#來獲取數據。引發異常顯示此錯誤消息。不,我沒有任何行。 – Bitterblue

回答

7

從表走樣AS排除 - AS可以選擇列表中使用,但不能在FROM子句

select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR 
from INFOR.RELFBR a, INFOR.RELXDB b 
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10') 
    and (a.CREATEDATE >= '01.01.2014 00:00:00') 
order by a.CREATEDATE 

例子:

SQL> select * from t_dummy t; 

         X               
-----------------------               
       9.0000               

SQL> select * from t_dummy as t; 
select * from t_dummy as t 
         * 
error in line 1: 
ORA-00933: SQL command not properly ended 

文檔:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm#i2126863

+0

+1 - 良好的捕獲。 –

+0

哇,我確定我在'FROM'的某處使用了'AS'。但是我錯了。我找不到任何東西。 Спасибо! – Bitterblue

+0

永遠歡迎:) –