Thursday, March 22, 2012

Calculated columns...

Hello,
can anyone help me with this?
SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
The point here is, if I use the following query
SELECT (A+B) AS X FROM TABLE WHERE (A+B) = 'sqdf'
the thing works, but for programming-technical reasons a have to use X
SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
What's wrong here?
Regards,
Kurt RogiersWHERE is evaluated before the field list, meaning that when you run
this, there is no column named "X" when the WHERE clause is evaluated.
Something like this will achieve the desired effect:
SELECT X
FROM (SELECT (A+B) AS X FROM TABLE) AS calcX
WHERE X = 'sqdf'
Kurt Rogiers wrote:
> Hello,
> can anyone help me with this?
> SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
> The point here is, if I use the following query
> SELECT (A+B) AS X FROM TABLE WHERE (A+B) = 'sqdf'
> the thing works, but for programming-technical reasons a have to use X
> SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
> What's wrong here?
> Regards,
> Kurt Rogiers|||You cannot use column aliases like this. You can only reference a column
alias in an ORDER BY clause, or outside of an inline query.
You can change the way you are coding this, to eliminate the "
programming-technical reasons " that require you to use "X".
You can also try one of these approaches:
select X from
(
SELECT (A+B) AS X FROM TABLE
)
where X = 'sqdf'
Create view MyView as
SELECT (A+B) AS X FROM TABLE
select X from MyView where X='sqdf'
"Kurt Rogiers" <k.rogiers@.skynet.be> wrote in message
news:%23jLUu%23viGHA.4056@.TK2MSFTNGP02.phx.gbl...
> Hello,
> can anyone help me with this?
> SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
> The point here is, if I use the following query
> SELECT (A+B) AS X FROM TABLE WHERE (A+B) = 'sqdf'
> the thing works, but for programming-technical reasons a have to use X
> SELECT (A+B) AS X FROM TABLE WHERE X = 'sqdf'
> What's wrong here?
> Regards,
> Kurt Rogiers
>|||Hello,
life can be SOOO easy!!!
Thanks a lot, the solution works wonderful
Regard,
Kurt
"Jim Underwood" <james.underwoodATfallonclinic.com> schreef in bericht
news:O%23wf3IwiGHA.1936@.TK2MSFTNGP04.phx.gbl...
> You cannot use column aliases like this. You can only reference a column
> alias in an ORDER BY clause, or outside of an inline query.
> You can change the way you are coding this, to eliminate the "
> programming-technical reasons " that require you to use "X".
> You can also try one of these approaches:
> select X from
> (
> SELECT (A+B) AS X FROM TABLE
> )
> where X = 'sqdf'
>
> Create view MyView as
> SELECT (A+B) AS X FROM TABLE
> select X from MyView where X='sqdf'
>
> "Kurt Rogiers" <k.rogiers@.skynet.be> wrote in message
> news:%23jLUu%23viGHA.4056@.TK2MSFTNGP02.phx.gbl...
>sql

No comments:

Post a Comment