cancel
Showing results for 
Search instead for 
Did you mean: 

How do you alias the results of a case statement

Former Member
0 Kudos

I am trying to create a derived table and I get the error

"each calculated column must have an explicit name"

I added the as shiptype to the end of the line and that did not work. Any thoughts?

shiptype = case when araddr.invno is not null then 'ADDR' else (case when arcadr.custno is not null then 'CADR' else 'CUST' end) end as shiptype,

Thanks

Jeff

Accepted Solutions (1)

Accepted Solutions (1)

amrsalem1983
Active Contributor
0 Kudos

>

> "each calculated column must have an explicit name"

> Jeff

you have to gave an alias for the column names

like

select salary*10 as new_salary from emp;

you made a calculation in the select statement and you need to give this calculation an Alias ( as new_salary)

make if for all the columns,

good luck

Amr

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Jeff,

your select statement should look like this...

select column1,column2,(case when araddr.invno is not null then 'ADDR' else (case when arcadr.custno is not null then 'CADR' else 'CUST' end) end) as shiptype from Table

This will work....

Cheers,

Ravichandra K

Former Member
0 Kudos

Hi Jeff,

your select statement should look like this...

select column1,column2,(case when araddr.invno is not null then 'ADDR' else (case when arcadr.custno is not null then 'CADR' else 'CUST' end) end) as shiptype from Table

This will work....

Cheers,

Ravichandra K

Former Member
0 Kudos

Hi Jeff,

It will depend on the db you are connecting to.

A standard one would be

SELECT

Dim1,

Dim2,

Active,

CASE

WHEN Active = 'Y'

THEN 'Active'

ELSE 'In Active'

END as ActiveText

FROM

My_Table

What is your DB?

Regards

Alan