Tolga E
Tolga E

Reputation: 12708

Custom Column on my select statement

I'm still new to SQL (Oracle).. Basically on a table I'm selecting from, there is a time stamp, and some are valid stamps and some are not (stored on a time stamp table).. I have a function I can use in 'where' clauses to return only the valid or invalid ones.

But sometimes I need to see all the records with an additional column that says 'Valid' or 'Invalid'.. I tried cases, something like this;

select *, case when function(stamp)=1 then 'Valid' else 'Invalid' 

but always gives me errors. I might be getting the syntax wrong. Can anyone help me figure this out?

Upvotes: 0

Views: 3448

Answers (2)

Try something like

select t.*,
       case
         when function(stamp) = 1
           then 'Valid'
           else 'Invalid'
       end as valid_flag
  from your_table t
  where <whatever>

Share and enjoy.

Upvotes: 2

Tony Andrews
Tony Andrews

Reputation: 132750

You're missing the END for the CASE:

select *, case when function(stamp)=1 then 'Valid' else 'Invalid' end

Upvotes: 5

Related Questions