Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Location
    BC Canada
    Posts
    61

    Unanswered: Select with an IF

    Is it possible to use an IF within a SELECT statement..

    I have a table with a text column

    cTIME (character)

    1:00 AM
    2:00 PM
    3:00 PM

    I want to create a 2nd column that wil contain the time in 24 hr?
    say

    select CTIME,IF (right(ctime,2)) = AM then CTIME ELSE CTIME + 12
    from table

    thanks?

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    It's CASE

    Code:
    select CTIME
    , CASE WHEN RIGHT(ctime,2) = 'AM' THEN CTIME 
                                                           ELSE CTIME + 12
      END
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2002
    Location
    BC Canada
    Posts
    61
    Originally posted by Brett Kaiser
    It's CASE

    Code:
    select CTIME
    , CASE WHEN RIGHT(ctime,2) = 'AM' THEN CTIME 
                                                           ELSE CTIME + 12
      END

    Thanks a bunch

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Are you trying to work with datetime data?

    Code:
    SELECT	  GetDate()
    	, CASE WHEN RIGHT(GETDATE(),2) = 'AM' THEN GETDATE() 
    					      ELSE GETDATE() + 12
    	  END
    aint gonna give you what you want if it is.....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Oct 2002
    Location
    BC Canada
    Posts
    61
    Originally posted by Brett Kaiser
    Are you trying to work with datetime data?

    Code:
    SELECT	  GetDate()
    	, CASE WHEN RIGHT(GETDATE(),2) = 'AM' THEN GETDATE() 
    					      ELSE GETDATE() + 12
    	  END
    aint gonna give you what you want if it is.....
    unfortuantly the people who did the data entry only put in 9am etc...

Posting Permissions

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