Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 use aliases in the where part - how ?

Author  Topic 

fabianus76
Posting Yak Master

191 Posts

Posted - 2008-02-09 : 10:16:58
Hello !

I wonder if I may use aliases in the Where part ?

this is not accepted :

SELECT
isnull((SELECT SUM(dbo.Answer.Evaluation) AS FIELD_2 FROM dbo.Answer WHERE(dbo.Answer.Question_ID = Quest.ID) AND(dbo.Answer.QuizUser_ID = 6)), 0) AS EvalutationResult,
Quest.ID AS Question_ID
FROM
dbo.Question Quest
WHERE
(Quiz_ID = 8) and EvalutationResult < 5d
ORDER BY
EvalutationResult

But I do not want to repeat all the stuff of EvoalutionResult once again.
Any idea?
Thanks a lot for any suggestion!

Regards,
Fabianus

my favorit hoster is ASPnix : www.aspnix.com !

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-09 : 10:22:10
Nope you cant use Aliases in where clause. You need to repeat entire thing. However you can use them in ORDER BY Clause.
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2008-02-09 : 10:52:18
Thanks Visakh16 !

Have a nice day,
Fabianus

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-11 : 04:49:10
or use derived table

SELECT * from
(
isnull((SELECT SUM(dbo.Answer.Evaluation) AS FIELD_2 FROM dbo.Answer WHERE(dbo.Answer.Question_ID = Quest.ID) AND(dbo.Answer.QuizUser_ID = 6)), 0) AS EvalutationResult,
Quest.ID AS Question_ID
FROM
dbo.Question Quest
WHERE
(Quiz_ID = 8)
) as t
where EvalutationResult < 5d
ORDER BY EvalutationResult

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2008-02-11 : 04:58:48
Hey Madhivanan,

of course - silly me. Thanks a lot for this hint !

Regards,
Fabianus

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page
   

- Advertisement -