Reputation: 91
I have this following piece of line when executed, gives me this error. How would I use exists here for the filter line 'next_NotedID' ? Thanks in Advance
Msg 116, Level 16, State 1, Line 27
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
this is my where clause
where (Name = 'File Review' and next_Name = 'File Review')
and (TYPECODE ='1200005' and next_Typecode = '1200005')
and ((HEADLINE like '%Follow up letter%')
and (next_Headline like '%Follow up letter%'))
and next_NotedID <> (SELECT ParentRef, max(NoteID)from Stg.IG_Note group by PARENTREF)
Upvotes: 0
Views: 36
Reputation: 50163
You can make your subquery
as correlated :
. . .
and next_NotedID <> (SELECT max(nt.NoteID)
from Stg.IG_Note nt
where nt.PARENTREF = outerqueryalise.ParentRef
);
If you are comparing with next_NotedID
with inner query max(NoteID)
then you can directly express it as
and next_NotedID <> (select max(nt.NoteID) from Stg.IG_Note nt);
Upvotes: 1
Reputation: 3591
change this line:
and next_NotedID <> (SELECT ParentRef, max(NoteID)from Stg.IG_Note group by PARENTREF)
to:
and next_NotedID <> (SELECT max(NoteID)from Stg.IG_Note group by PARENTREF)
You can not select more then 1 field in a sub select when using <>. If this returns more then one possible value you would need to change it to NOT IN instead of <>
Upvotes: 0