>I used the following.
>
>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 S
>
>
>Thanks Again
You could have used CTE instead of the table variable - not sure which one is more effective.
If it's not broken, fix it until it is.
My Blog