Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query Help
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
00808214
Message ID:
00808260
Vues:
13
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


>Hi Eric,
>
>Try
DECLARE @IdList varchar(8000)
>SELECT @IdList = ISNULL(@IdList + ', ', '') + StudentId
> FROM survey
> WHERE interest IN (3,59)
> GROUP BY StudentId
>SELECT @IdList
>
>>I have a table that contains a record of a student id and an interest they marked off on a survey.
>>
>>StudentID, interest
>>3333333, 5
>>3333333, 45
>>3333333, 2
>>2222222, 45
>>2222222, 3
>>1111111, 3
>>1111111, 45
>>1111111, 59
>>1111111, 23
>>
>>
>>I want to make a query that will allow someone to enter a list of ids and return the ID's of students have selected those interests. EX. when someone enters 3 and 45, it will return 2222222, and 1111111.
>>
>>Right now I can only get it by doing
>>
>>select x.studentid
>>from 	(select studentid from studentsurvey where interest = 3) x,
>>	(select studentid from studentsurvey where interest = 45) y
>>where x.studentid = y.studentid
>>
>>
>>Obvisouly this wount work too well if there is a dynamic number of interest to match. Any ideas.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform