Home All Groups Group Topic Archive Search About
Author
8 Jun 2006 1:30 PM
Kurt Rogiers
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

Author
8 Jun 2006 1:39 PM
Tracy McKibben
WHERE 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:
Show quote
> 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
Author
8 Jun 2006 1:49 PM
Jim Underwood
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'


Show quote
"Kurt Rogiers" <k.rogi***@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
>
>
Author
8 Jun 2006 2:00 PM
Kurt Rogiers
Hello,

life can be SOOO easy!!!
Thanks a lot, the solution works wonderful

Regard,
Kurt

Show quote
"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.rogi***@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
>>
>>
>
>

AddThis Social Bookmark Button