DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: using CASE in CTAS ??

  1. #1
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346

    using CASE in CTAS ??

    Can I use a CASE statement with a CTAS statement....

    What I want to do is have date_created = date_of_inbound
    only if the sub-select statement row has communication_code = 'I'.

    If it doesn't then I want the default date_created.

    The pseudo code(?) is something like this....

    create table TEST as
    (
    select w_member.membership_number,

    (case w_communication.communication_code
    when 'I' then minval date_created
    else date_created),

    recruiting_channel

    from w_member,(select membership_number,
    min(date_of_inbound) minval
    from w_communication
    group by membership_number) abc
    where w_member.membership_number = abc.membership_number(+))
    );

    Any help would be appreciated.

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Why do you think that you can't use CASE? Getting an error message?
    By the way, i notice that you don't have a column alias on the case.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346
    I've not used it before, and need advise on the syntax, plus do I need an alias ?

  4. #4
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    409
    Code:
    SQL>  ed
    Wrote file afiedt.buf
      1  create table case_test as (select case when 0 = 1 then 'ONE' else 'ZERO'
      2          end
      3*       from dual)
    SQL> /
    create table case_test as (select case when 0 = 1 then 1 else 0
                                      *
    ERROR at line 1:
    ORA-00998: must name this expression with a column alias
    
    
    Elapsed: 00:00:00.25
    
    
    SQL>  ed
    Wrote file afiedt.buf
      1   create table test_caseb as (select (case when 0 = 1 then 'ONE' else 'ZERO'
      2           end ) cola
      3*        from dual)
    SQL> /
    
    Table created.
    
    Elapsed: 00:00:00.09

    So yes, 'alias' is needed.
    -- Dilip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width