2017-03-07 62 views
-1

我有一個具有以下字段的表:多部分標識符「IncomeExpenses.OperationId」無法綁定

OperationID, 
Date, 
TotalExpenses, 
TotalIncome 

我使用下面的SQL查詢來獲取基於TotalExpensesTotalIncome之間的區別指定OperationID

select 
    (select (Date) from IncomeExpenses) 
,(select (totalincome) from IncomeExpenses) 
-(select (totalexpenses) from IncomeExpenses) 
where IncomeExpenses.OperationId ='1' 

但是我得到這個錯誤:

The multi-part identifier "IncomeExpenses.OperationId" could not be bound

我可能會做錯什麼?

回答

0

如果這是SQL查詢應該看起來像:

select Date, (totalincome - totalexpenses) as differencetotal 
from IncomeExpenses where OperationId ='1' 
2

爲你寫的子查詢選擇單獨列的一些原因。外部查詢中沒有FROM子句,因此您不能編寫引用任何表的where子句。爲什麼你不只是寫作

select date, 
     totalincome-totalexpenses 
from IncomeExpenses 
where OperationId=1 
+0

謝謝你,這對我有效 –

相關問題