|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
How to update rows based on current row data?
Hi... forum newbie here... I tried a couple searches... couldn't really find what I'm looking for...
Here is my question: Lets say I have the following list of dates in 3 columns First date, last date, and difference of those dates.... first_timestamp second_timestamp time_stamp_diff Jul 5 2003 1:43PM Jul 7 2003 1:43PM NULL Jul 5 2003 2:10PM Jul 7 2003 8:30AM NULL Jul 5 2003 7:52PM Jul 7 2003 3:07PM NULL Jul 5 2003 9:12PM Jul 7 2003 8:28AM NULL How can I write a query that goes in and updates column 3 with the difference of those column 1 and 2? I tried something like below but obviously it didn't work since the sub query returns more than one result... what am I missing? select time_stamp_diff = (datediff(hh,(select first_timestamp from db),(select second_timestamp from db))) from db Basically the bottom line is I want to update each time_stamp_diff row based on the 2 columns before it. I have no idea how to do that with a for loop, update sub query or anything becuase sql craps out if you return more than one row with a sub expression.... I'm confused! Any advice is appreciated! ![]() |
|
#2
|
|||
|
|||
|
Woops, I knew it was something simple:
Solution: update blah set time_stamp_diff = datediff(hh,convert(datetime,feedback_timestamp,11),convert(datetime,app_timestamp,11)) plus other syntax for anyone who cares. |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > How to update rows based on current row data? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|