Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 21st, 2003, 01:34 PM
twifosp twifosp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 twifosp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old July 21st, 2003, 03:18 PM
twifosp twifosp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 twifosp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > How to update rows based on current row data?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway