Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with Stored Procedure
Message
From
02/02/2011 07:44:59
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01498262
Message ID:
01498270
Views:
43
Sergey,

That was fast and it does the trick. Just tested and works perfect. Thank you very much. Just for my understanding, is the Select 1 mean only one record? In the data that shouldn't happen but is that to prevent in case it was found? Also, how does the sub query return a householdID to match to the household?
Thanks
Tim

>Try
>
>
>SELECT *
>  FROM Household 
>  WHERE ApplicantID = @PersonId  
>    OR EXISTS (SELECT 1 FROM HouseholdMembers WHERE HouseholdID = Household.HouseholdID AND PersonId =  @PersonId)
>
>
>>
>>I have to admit I am weak on this topic and would like to get better. I need a stored procedure where I can retrieve a record from a single table but the parameter passed in could be a match to a column in this table or it could be found in another. Here is the table structure.
>>
>>
>>*** Household ***
>>HouseholdID (UniqueID)
>>LocationID (UniqueID)
>>ApplicantID (UniqueID)  -> 1-1 to Persons
>>
>>*** HouseholdMembers ***
>>HouseHoldID  (UniqueID)         -> HouseHold
>>PersonId  (UniqueID)              -> Person
>>RelationshipRoleID (UniqueID)  ->RelationshipRole
>>DateAddedToHousehold (DateTime)
>>
>>
>>What I need is to obtain the single row from Household and pass in a PersonID. The PersonID may be found in household in the ApplicantID column but if not, then it would be found in the HouseholdMembers table and would give the HouseholdID value there to get the row from.
>>
>>Any help appreciated to get me pointed to creating this stored procedure. Thanks
>>Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform