Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Using Result of SQL Case Statement

When I run this statement it works.  However when I uncomment the 2nd bottom line it tells me
Invalid column name 'AlleqGEOLN'
even though I created this in the case statement.  What am I doing wrong?

select cq.dscode,
cq.cntrycode,
    case
      when al.GEOLN = 'OE' then 'AT'
      when al.GEOLN = 'CN' then 'CA'
      when al.GEOLN = 'BD' then 'DE'
      when al.GEOLN = 'UK' then 'GB'
    else al.GEOLN
    end as AlleqGEOLN,
cq.dsquotename,
cq.IsPrimaryQuote,
al.isinid,
cq.CoverageCode,
al.[coverage Indicator],
cq.StatusCode,
al.estat
from cntryquote cq
inner join alleq al
on cq.dscode=al.code
where cq.isdeleted='N'
--and AlleqGEOLN <> cq.cntrycode
order by cntrycode,dsquotename
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

try this
and al.GEOLN  <> cq.cntrycode
instead of this
and AlleqGEOLN <> cq.cntrycode
ASKER CERTIFIED SOLUTION
Avatar of JimFive
JimFive
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2

ASKER

Thanks.