Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with Stored Procedure
Message
De
02/02/2011 12:15:30
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01498262
Message ID:
01498341
Vues:
36
Thanks Naomi,

I am understanding now.

>>Thanks Sergey,
>>
>>The puzzling part for me was how the primary Select statement gets a match to the subquery. While this probably isn't valid SQL, I would have expected something like this where we specify we are looking for HouseholdID in the subquery to match the HouseholdID in the main query.
>>
>>SELECT *
>>  FROM Household 
>>  WHERE ApplicantID = @PersonId  
>>    OR HouseholdID = (SELECT HouseholdID FROM HouseholdMembers WHERE PersonId =  @PersonId)
>>
>
>
>>In that case where trying to specifically select HouseholdID from the subquery.
>>
>>I guess it is this part of the subquery that does that magic. WHERE HouseholdID = Household.HouseholdID AND PersonId = @PersonId
>>
>>Basically it works so I am happy, but just trying to figure out so I understand.
>>Thanks a bunch, I think I am making sense of it now.
>>Tim
>>
>
>What you wrote is essentially the same as EXISTS query. But EXISTS is just a better syntax and also it does not suffer from the NULL problem that IN query suffers.
>
>In order to CONNECT outer and inner queries, you use this
>
>select * from HouseHold H1
>where exists (select 1 (you can put * with the same effect here)
>from HouseholdMembers M where H1.HouseHoldID = M.HouseHoldID -- this is the connection between outer and inner
>AND M.PersonID = @PersonID)
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform