Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case in subquery

Author  Topic 

dzabor
Posting Yak Master

138 Posts

Posted - 2011-03-03 : 15:55:04
I am trying to use a subquery to pull a field in a script.

select n.id,
n.Last_Updated as 'Last Updated',
(SELECT Case
WHEN member_Type in('OWNER','EXEC','AFF','STU','HLM') THEN 'Member'
else 'Guest Member'
END as NewMemberType
from name ) as 'Member Type Code',
'' as 'Primary Group Code',
n.Last_Name as 'Last Name',
n.First_Name as 'First Name'
from name n

I get the error 'Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'

I tried to use Top 1, but it returns the same values for all, 'Member'.

Any idea how I can get it to return that field value as 'Member' for the first set specified and 'Guest Member' for the rest?

Thanks!

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-03 : 15:58:32
Do SELECT DISTINCT CASE

But I'm Sure that won't solve the problem

Problem is, you need to understand the relationships between the data you are trying to pull

Please post DDL, sample Data in DML format and the expected results

Thanks



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -