Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Help
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
00808214
Message ID:
00808264
Views:
15
This message has been marked as the solution to the initial question of the thread.
Hi Eric

Sorry, I misread your original post. Try
DECLARE @IdList varchar(8000)
SELECT @IdList = ISNULL(@IdList + ', ', '') + StudentId
	FROM survey 
	WHERE StudentId IN ( SELECT StudentId FROM survey 
		WHERE interest IN (3,45)
		GROUP BY StudentId 
		HAVING COUNT(*) = 2 )
GROUP BY StudentId
SELECT @IdList
As you can see, ther are two "variables" in this query: the list of interests '(3,45)' and number of valuses in the list - '2'.


>Thanks for your help Sergey, but this is technically an "OR" I think, Im looking to perform an "AND."
>
>660	0014388	20.0
>689	0169109	2.0
>691	0169108	2.0
>696	0018490	2.0
>699	0022895	5.0
>700	0022895	6.0
>701	0168595	2.0
>702	0168595	5.0
>703	0168595	6.0
>
>
>On this data looking for options 2 and 5, there should only be one record returned, '0168595' because that person has both options selected. Does that make sense?
>
>Eric
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform