BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Update TADOQuery from a Select TADOQuery

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Laurie McIntosh
Guest





PostPosted: Wed Aug 11, 2004 7:14 am    Post subject: Update TADOQuery from a Select TADOQuery Reply with quote



Howdy people,

Stuck. I've got two tables. I want to update Table B with a count of
related fields in Table A.

So: I can

SELECT DISTINCT D.RepDate, D.AMPM, D.Route, COUNT(DISTINCT
D1.ManifestNo) AS NoSailings
FROM `daterep` D, mfest` D1
WHERE
(D.AMPM = 1.0)
AND (D1.SailDate = D.RepDate)
AND (D1.SailTime < 1200.0)
AND (D1.Route = D.Route)
GROUP BY D.RepDate, D.AMPM, D.Route

[mfest is Table A and repdate is Table B - these are tables in a MYSQL
database. Delphi7 Enterprise, by the way.]

And this works fine. I've got this code in a TADOQuery on a form and I
open it. I know it works fine, because I can see it in a DBGrid. Now.
The four fields I'm returning exist in Repdate. I want to update the
NoSailings field in Repdate with the returned.

What's the best way to do this? I COULD while-step through the TADOQuery
dataset and record by record locate and update them, but surely there's
another way. I'd like to fire an update query off this, but can't work
out how to nest the select and update... or, maybe I can do another
query using the first query as a source... or...?

What's the canonical way to do an update using a calculated select as a
source?

Regards,

---=Laurie
Back to top
Laurie McIntosh
Guest





PostPosted: Fri Aug 13, 2004 4:29 am    Post subject: Re: Update TADOQuery from a Select TADOQuery Reply with quote



Brian Bushay TeamB wrote:


Quote:
What your looking for is an Update query using a correlated subquery.
I don't know MSQL syntax

In SQL server it would be something like this

Update Repdate
Set NoSailings = D.NoSailings
From RepDate D1 Join
Select (repdate, Route, Count(ManifestNo) as NoSailings) from mFest Group
by repdate, Route) D
D1.SailTime < 1200.0



Thanks Brian. That's what I was looking for. It don't work, but probly
because of the flavour of database.


---=L

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.