Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    3

    Unanswered: Select Case Columns

    When I try to do the following SQL statement to select a different column it gives the error below as one is a date and one a number

    [I]ORA-00932: inconsistent datatypes: expected DATE got NUMBER

    Select
    CASE WHEN 2=1 THEN DATE+TP_PERIOD/48 ELSE TP_PERIOD END DATE,


    Is there a way to use TOCHAR or something so I can get either result in one column?

    The two outputs would be as below

    DATE
    1
    2
    3
    48

    or in the below format if true

    DATE
    3/05/2012 0:30
    3/05/2012 1:00
    3/05/2012 23:30
    4/05/2012 0:00

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    I don't know what you have.
    I don't know what you see.
    I don't know what you do.
    Please post CREATE TABLE statements for all tables involved.
    Please post INSERT statements for test/sample data that produces the expected/desired results.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2012
    Posts
    84
    Quote Originally Posted by bradh_nz View Post
    CASE WHEN 2=1 THEN DATE+TP_PERIOD/48 ELSE TP_PERIOD END DATE,

    Is there a way to use TOCHAR or something so I can get either result in one column?
    Yes, TO_CHAR should work
    Code:
    CASE WHEN 2=1 THEN to_char( DATE+TP_PERIOD/48 )
                  ELSE to_char( TP_PERIOD END DATE )
    END ,

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    CASE WHEN 2=1
    Will never true, so it will always use the ELSE part.

Posting Permissions

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