Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best Practice For the Following Scenario
Message
 
 
À
25/03/2003 14:36:16
Jason Dalio
Northern Interior Regional Health Board
Prince George, Colombie Britannique, Canada
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00769884
Message ID:
00769982
Vues:
22
This message has been marked as the solution to the initial question of the thread.
Jason,

Try OUTER JOIN
SELECT Activity.ActivityDesc, Activity.ActivityDesc, 
	Data.Value, StaffActivity.IsVisible
FROM Activity 
LEFT JOIN StaffActivity ON StaffActivity.ActivityID = Activity.ActivityID 
LEFT JOIN Data ON Data.ActivityID = StaffActivity.ActivityID 
			AND Data.StaffID = StaffActivity.StaffID 
WHERE Data.StaffID = 5
>Hi SQLers. I am writying an app using a Visual Basic front end to do the queries bu ti wanted to hit up the SQL knowledge here to see if I can make this more efficient. Here is the simplified version.
>
>
>--------------------------
>Table1: Activities
>
>ActivityID
>ActivityDesc
>--------------------------
>Table2: StaffActivities
>
>StaffID
>ActivityID
>IsVisible
>--------------------------
>Table3: Data
>
>Date
>StaffID
>ActivityID
>Value
>--------------------------
>
>
>On the form there is a grid that i want to show all of the values in activities and all of the values from Table3 where the StaffID, ActivityID and Date match for the current selected date. Right now I am having to use 3 separate queries and code manipulation to achieve this. I keep thinking there must be a better way.
>
>I'm using the following query to get the main results:
>
>SELECT Activity.ActivityDesc, Activity.ActivityDesc, Data.Value, StaffActivity.IsVisible
>FROM Activity 
INNER JOIN (StaffActivity 
INNER JOIN Data ON (Data.ActivityID = StaffActivity.ActivityID) 
AND (StaffActivity.StaffID = Data.StaffID)) 
ON Activity.ActivityID = Data.ActivityID
>WHERE (((Data.StaffID)=5))
>
>
>This of course only gives me values where there is an entry in the StaffActivities table. I want the users to always see the full list of Activities (in case someone adds a new one in after the fact) reagardless of if they have gone into their profile to mark activities as visible or invisible.
>
>I know this message is kind of convoluted but i hope it conveys my meaning anyway. Thanks.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform