query to fill one column with othe column in same table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sva0008
    New Member
    • Apr 2008
    • 19

    query to fill one column with othe column in same table

    have a table that have 5 colums

    ID, month , day , year and Date

    The table have month , day , year column as blank i want to write a query so that i can

    update month , day and year column using date column as in month part of that date , day part of that date and year part of that date . ID is a primary key in Table.

    Any help is much appreciated

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Code:
    +----+------------+------+------+------+
    | id | date       | dd   | mm   | yyyy |
    +----+------------+------+------+------+
    |  1 | 2008-10-20 | NULL | NULL | NULL |
    |  2 | 2007-12-10 | NULL | NULL | NULL |
    +----+------------+------+------+------+
    [code=sql]update table set dd=substr(date, 9,2), mm=substr(date, 6,2), yyyy=substr(dat e,1,4)[/code]result table:
    Code:
    +----+------------+------+------+------+
    | id | date       | dd   | mm   | yyyy |
    +----+------------+------+------+------+
    |  1 | 2008-10-20 | 20   | 10   | 2008 |
    |  2 | 2007-12-10 | 10   | 12   | 2007 |
    +----+------------+------+------+------+
    Ronald

    Comment

    Working...