Update statement conditioned to two columns, but for some values only

Hi This is my my sample data:
with Table_1        
as
(
      select '20:00' incident_time, 'WEDNESDAY' Day, 'N' Weekend,  '' Weekend_Alt   from dual
      union all
      select '18:00' incident_time, 'SATURDAY' Day, 'Y' Weekend,  '' Weekend_Alt from dual
      union all
      select '19:00' incident_time, 'FRIDAY' Day, 'N' Weekend, '' Weekend_Alt from dual
      union all
      select '11:00' incident_time, 'FRIDAY' Day, 'N' Weekend, '' Weekend_Alt from dual
)
select *
  from Table_1
I want to perform an update as shown below
Update Table_1 tt
  
 SET Weekend_Alt = (CASE WHEN TO_CHAR(tt.day,'fmDAY') IN ('FRIDAY AND TIME >= 19:00','SATURDAY','SUNDAY') THEN 'Y' ELSE 'N' END)

I realize the syntax is wrong but just want to give you an idea of what I want to achieve.
Final result should look like this:
with Table_1        
as
(
      select '20:00' incident_time, 'WEDNESDAY' Day, 'N' Weekend,  'N' Weekend_Alt   from dual
      union all
      select '18:00' incident_time, 'SATURDAY' Day, 'Y' Weekend,  'Y' Weekend_Alt from dual
      union all
      select '19:00' incident_time, 'FRIDAY' Day, 'N' Weekend, 'Y' Weekend_Alt from dual
      union all
      select '11:00' incident_time, 'FRIDAY' Day, 'N' Weekend, 'N' Weekend_Alt from dual
)
select *
  from Table_1
Thanks in advance!

Banner:
Oracle Database 11 g Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production."
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
with Table_1
as
(
      select to_date('01-JUL-2009 20:10','DD-MON-YYYY HH24:MI') incident_date    from dual
      union all
      select to_date('23-MAR-2010 12:12','DD-MON-YYYY HH24:MI') incident_date from dual
      union all
      select to_date('25-JUL-2010 23:30','DD-MON-YYYY HH24:MI') incident_datet from dual
      union all
      select to_date('09-JAN-2010 08:30','DD-MON-YYYY HH24:MI') incident_date from dual
      union all
      select to_date('08-JAN-2010 08:30','DD-MON-YYYY HH24:MI') incident_date from dual
      union all
      select to_date('08-JAN-2010 20:30','DD-MON-YYYY HH24:MI') incident_date from dual
      union all
      select to_date('26-JUL-2010 00:00','DD-MON-YYYY HH24:MI') incident_datet from dual
)
select incident_date, to_char(incident_date,'Day'),
    case
        when incident_date between trunc(incident_date,'IW') + 4 + 19/24
                               and trunc(incident_date,'IW') + 7
        then 'Y' else 'N'
    end
from Table_1 t;

So your update

update table_1 tt
set weekend_alt =
    case
        when incident_date between trunc(incident_date,'IW') + 4 + 19/24
                               and trunc(incident_date,'IW') + 7
        then 'Y' else 'N'
    end;

But it begs the question if it's a good idea to store these derived data

Published by: 3360 November 8, 2011 10:14

Tags: Database

Similar Questions

Maybe you are looking for

  • How can I send faxes directly to the computer?

    I have an Officejet Pro 8500 a HP all-in-one.  My computer operating system is windows Vista home and the printer is connected wireless to my home network.  I want to know how to send a fax received from the printer directly to the computer without h

  • Re: Wireless has stopped working on my Equium L40 (PSL41E)

    Hi guys. With the help of my laptop wireless this morning and all was fine, then all of a sudden, it loses the connection. Tried different methods to restore the link, update driver downloaded but no luck. The wireless light on the front of the lapto

  • When I optimize my FP at this time here my gauge is not in shap... any idea... ???

    Hello When I optimize my FP at this time here my gauge is not in shap... any idea... ???

  • Qwest and Windows Live

    Qwest has moved my live mail windows q.com account for myqwest.com? I don't like the new Web site for my email.  Is there anything I can do to get a different messaging platform without changing my email address?  It is said that they do not support

  • How to increase Mins to DateTime...

    Hello I have a date past say Sun may 24 18:40:00 GMT 2009 I have uncreated 10mins to this day... but unable to do so... Can someone pls help increarse the minutes in 10 minutes date... kindly help...