我正在處理存儲過程。該結構的構建方式是我們使用其他過程將數據存儲在表中,然後我們會調用這些數據來獲取報告以加快系統的速度。好吧,在這種特殊情況下,我已經獲得了一張表中所需的全部數據,但我想從另一張表中提取數據。在這一個我想計算兩次之間的值。如何使用子查詢計算值
create table #Temp (row int IDENTITY (1, 1) NOT NULL, Col01 varchar(100),
Col02 varchar(100), Col03 varchar(100),Col04 varchar(100),Col05 varchar(100),
Col06 varchar(100),Col07 varchar(100),Col08 varchar(100),
Col09 varchar(100),Col10 varchar(100),Col11 varchar(100),Col12 varchar(100))
Insert into #Temp (Col01,Col02,Col03,Col04,Col05,Col06,Col07,Col08,
Col09,Col10,Col11,Col12)
Select A,B,C,D,E,((Select s.Counter from
TableS s where s.tid = '8:00'and s.Namn = h.Namn)
-
(Select s.Counter from Maintenance.dbo.TableS s where s.tid = '17:00'
and s.Namn = h.Namn)), F, G,
H,I,J,K
from TableH h
order by Tid
我收到錯誤消息:我的猜測是我不能在子選擇中使用條件?
Msg 512, Level 16, State 1, Procedure Top_Secret, Line 16
Subquery returned more than 1 value.
This is not permitted when the subquery follows =,
!=, <, <= , >, >= or when the subquery is used as an expression.
AAAH,我怎麼能錯過。它爲我做了伎倆:)乾杯 – SterlinkArcher