how can i update my table with the elapasedsecond as a new coloumn

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalthiruvathilil
    New Member
    • Dec 2009
    • 4

    how can i update my table with the elapasedsecond as a new coloumn

    i have generated the difference between two rows of my data using this code.....
    now i have the ElapsedSecond as one new row how can i save it into my table??


    SELECT *,
    DATEDIFF(second , A.End_Time,
    (SELECT MIN(Start_Time)
    FROM Callbycall as B
    WHERE A.Agent = B.Agent
    AND A.Start_Time < B.End_Time)) as ElapsedSecond
    FROM Callbycall as A
  • nbiswas
    New Member
    • May 2009
    • 149

    #2
    Try something like

    Code:
    insert into tablename
    select * from tablename
    syntax

    e.g.

    Code:
    [B]insert into Callbycall[/B]
    
    SELECT *,
    DATEDIFF(second, A.End_Time,
    (SELECT MIN(Start_Time)
    FROM Callbycall as B
    WHERE A.Agent = B.Agent
    AND A.Start_Time < B.End_Time)) as ElapsedSecond
    FROM Callbycall as A

    Hope this helps

    Comment

    • nirmalthiruvathilil
      New Member
      • Dec 2009
      • 4

      #3
      will this code help me to update the table which i am having..
      this is insert i would like to hava a update statement which would help me to insert the values.

      Comment

      • nbiswas
        New Member
        • May 2009
        • 149

        #4
        Solution to how can i update my table with the elapasedsecond as a new coloumn

        The general syntax for this case is

        Code:
        UPDATE <destinationtablename>
        SET <destinationtablename.columnname> = <sourcetablename.columnname>
        FROM < sourcetablename >
            INNER JOIN < destinationtablename >
            ON (<destinationtablename.columnname> = <sourcetablename.columnname>);
        Coming to your program, try this(you may need to modify a bit as I don't have the exact schema)

        Code:
        UPDATE DESTINATION_TABLE
        SET DESTINATION_TABLE.ElapsedSecond= S.ElapsedSecond
        FROM 
        (SELECT *,
        DATEDIFF(second, A.End_Time,
        (SELECT MIN(Start_Time)
        FROM Callbycall as B
        WHERE A.Agent = B.Agent
        AND A.Start_Time < B.End_Time)) as ElapsedSecond
        FROM Callbycall as A) S
        
        INNER JOIN DESTINATION_TABLE D
        ON D.JOIN_FIELD_NAME = S.JOIN_FIELD_NAME
        I have given a similar response to you question here how to insert the value of a function in the coloum

        Hope this helps

        Comment

        Working...