Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2011
    Posts
    78

    Unanswered: updating the table

    I wanted to update my table. If my new column is derived based on the existing column, how do I go about that. For example, if column H has different numbers.

    I want to set 0-5 from column h and make it as values "12a-6a" in column D.

    6-10 from column h and make it something else in column D.

    Please let me know if anyone knows. Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    please show your current table layout

    we could guess what you're trying to do, but that would waste our time and yours
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2011
    Posts
    78
    Columns: Realtime, hour and Part

    Part is an empty column, it's values are derived from hour.

    For example the hour column has numbers like 0,1,2,3,5,6,7,8,9,11,12...etc

    The Part column wants to show that for hours 0 to 5, it is equal to "12a-6a" , for hourd 6 to 10 it is equal to "something else"

  4. #4
    Join Date
    Jul 2011
    Posts
    78
    update EDA.TIME
    Set Daypart= '12a-6a' if HOUR >='0' and Hour <='5'

    '6a-12p' if hour>='6' and hour <='11'
    '12p-6p' if hour>='12' and hour<='15'
    '6p-12a' if hour>='16' and hour <='23'


    This is the idea, but I dunno how to incorporate that into the update statement syntax.

  5. #5
    Join Date
    Jul 2011
    Posts
    78
    I figured it out, thank you

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Mangolili View Post
    I figured it out, thank you
    please show

    others with similar problems, when they search the site, will find this thread, so it's only fair that you post your solution
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jul 2011
    Posts
    78
    This is my solution and it works

    update EDA.TIME

    Set Part= '12a-6a' where HOUR >='0' and Hour <='5'

Posting Permissions

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