By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

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

P: 4
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
Dec 9 '09 #1
Share this Question
Share on Google+
3 Replies


nbiswas
100+
P: 149
Try something like

Expand|Select|Wrap|Line Numbers
  1. insert into tablename
  2. select * from tablename
syntax

e.g.

Expand|Select|Wrap|Line Numbers
  1. insert into Callbycall
  2.  
  3. SELECT *,
  4. DATEDIFF(second, A.End_Time,
  5. (SELECT MIN(Start_Time)
  6. FROM Callbycall as B
  7. WHERE A.Agent = B.Agent
  8. AND A.Start_Time < B.End_Time)) as ElapsedSecond
  9. FROM Callbycall as A

Hope this helps
Dec 9 '09 #2

P: 4
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.
Dec 10 '09 #3

nbiswas
100+
P: 149
The general syntax for this case is

Expand|Select|Wrap|Line Numbers
  1. UPDATE <destinationtablename>
  2. SET <destinationtablename.columnname> = <sourcetablename.columnname>
  3. FROM < sourcetablename >
  4.     INNER JOIN < destinationtablename >
  5.     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)

Expand|Select|Wrap|Line Numbers
  1. UPDATE DESTINATION_TABLE
  2. SET DESTINATION_TABLE.ElapsedSecond= S.ElapsedSecond
  3. FROM 
  4. (SELECT *,
  5. DATEDIFF(second, A.End_Time,
  6. (SELECT MIN(Start_Time)
  7. FROM Callbycall as B
  8. WHERE A.Agent = B.Agent
  9. AND A.Start_Time < B.End_Time)) as ElapsedSecond
  10. FROM Callbycall as A) S
  11.  
  12. INNER JOIN DESTINATION_TABLE D
  13. 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
Dec 11 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.