Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add columns to select *

In SQL Server I used to do something like this to add extra columns to a select:

select *,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end as end_date_modified
from WEIGHTED_AVERAGE w1

Yet the following in Oracle causes "ORA-00923 FROM keyword not found where expected":

select *,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end end_date_modified
from WEIGHTED_AVERAGE w1

I've searched all over but can't figure out how to achieve this in Oracle.

like image 817
m.edmondson Avatar asked Mar 27 '26 08:03

m.edmondson


1 Answers

try this

select w1.*,
        case
        when w1.start_date < w2.start_date then
            to_date(w2.START_date, 'DD/MM/YYYY') - 1
        else
        to_date(w1.end_date, 'DD/MM/YYYY')
        end end_date_modified
from WEIGHTED_AVERAGE w1
like image 147
Vitor Freitas Avatar answered Mar 28 '26 23:03

Vitor Freitas