Question

I'm working on a stored procedure. The structure is built in the way that we use other procedures to store data in tables, which we then call upon to get reports to make our systems faster. Well well, in this particular case I've got all data needed in one table, but I want to extract data from another table. In this one I want to calculate a value between two occasions.

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

I get the error message: My guess is that I cannot use conditions in the subselects?

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.
Was it helpful?

Solution

Select TOP 1 s.Counter from Maintenance.dbo.TableS s where s.tid = '17:00' and s.Namn = h.Namn

OTHER TIPS

The error is self describing.. There is more than one row matching your filter. Modify your subquery in a way that only one row is matched.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top