views:

40

answers:

1

Hi I'm working on a project which requires I use a large number of columns in my Access SQL queries. A typical query contains several fields such as the one below:

SELECT ([Score1]+[Score2]+[Score3])*.5 AS [Scores], [Subject] FROM [ScoresTable]
WHERE ([Score1]+[Score2]+[Score3])*.5 > 500

Is there any way to assign the value of ([Score1]+[Score2]+[Score3])*.5 to a variable so I could in effect write something like:

SELECT ([Score1]+[Score2]+[Score3])*.5 AS [Scores] *= VAR*, [Subject] 
FROM [ScoresTable] WHERE *VAR* > 500

If it is possible, could you please show me how to achieve such results?

Thank you.

A: 
SELECT sq.Scores, sq.Subject
FROM (
    SELECT (Score1+Score2+Score3)*.5 AS Scores, Subject
    FROM ScoresTable
    ) AS sq
WHERE sq.Scores > 500;

If Score1, Score2, or Score3 can be Null, you may want to use the Nz function to substitute zero for Null.

HansUp
I tried this and it worked.Thanks.
Alex Essilfie