Reputation: 12613
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.
Upvotes: 1
Views: 7677
Reputation: 97101
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.
Upvotes: 1