Question

I have a statement where i want to use the value of alias in my sql statement . How can i use this. Is there any possible way to use the alias value.

   SELECT ORDERID ,clientnum,ID, READYDATE,
case when ID=56 then 'O'
ELSE
CASE when ID=65 then 'A'
ELSE
  'NONE'
END 

END 
 AS LOctaion  -- want to use this alias below in where clause 

from orde_

where READYDATE='2014-05-09' AND  LOctaion='A' 

Is this possible how can i do this . Thanks for your comments

Was it helpful?

Solution

You could do this:

SELECT
    *
FROM
(
    SELECT 
        ORDERID ,
        clientnum,
        ID, 
        READYDATE,
        (
        case when ID=56 then 'O'
        ELSE
        CASE when ID=65 then 'A'
        ELSE
          'NONE'
        END 
        END) AS LOctaion

    from orde_
) AS tbl
where tbl.READYDATE='2014-05-09' AND  tbl.LOctaion='A' 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top