Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Statement How To
Message
 
À
09/06/2009 14:42:02
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01404764
Message ID:
01404787
Vues:
29
>It's pretty complicated to say the least. I was hoping I would be able to write a statement that just checked for a students existence in each subquery. I was thinking of using ICASE but I wasn't sure if I could use that in conjunction with "Where exists ( Select * from level5)".

You could use a table variable for this and then join it to the query:
DECLARE @StdLevel TABLE (StidenId int, Level int)

INSERT INTO @StdLevel
SELECT StudentId, MAX(Level)
FROM (SELECT StudentId, 1 AS Level
             FROM Level1
      UNION ALL
      SELECT StudentId, 2 AS Level
             FROM Level2
      UNION ALL
      SELECT StudentId, 3 AS Level
             FROM Level3
      UNION ALL
      SELECT StudentId, 4 AS Level
             FROM Level4
      UNION ALL
      SELECT StudentId, 5 AS Level
             FROM Level5) Levels
GROUP BY StudentId

SELECT .....
FROM ...
INNER JOIN @StdLevel StdLevel1 ON ....StudentId = StdLevel1.StudentId AND StdLevel1.Level = 1
...
Something like that.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform