views:

29

answers:

2

Hi Guys, 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 funtion(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?

Thanks.

+4  A: 

You're missing the END for the CASE:

select *, case when funtion(stamp)=1 then 'Valid' else 'Invalid' end
Tony Andrews
oh i see.. thank you..
Wonder
+2  A: 

Try something like

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

Share and enjoy.

Bob Jarvis