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 

Delete records from table1 where in table2 ...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
Giovanni Filippini
Guest





PostPosted: Tue Apr 06, 2004 7:18 am    Post subject: Delete records from table1 where in table2 ... Reply with quote



Hello to the Group,
(Delphi_6 - Paradox).
I need to delete records in Table1 if any record in
table2 with same key has a date.
Unfortunately I have a field named 'key'.
Here my code :
( 'key' and 'kkk' are the key fields to match )

query1.sql.clear;
query1.sql.add('delete FROM "table1.db"');
query1.sql.add('WHERE "key" IN');
query1.sql.add('(SELECT kkk FROM "table2.db" where date_ended >
:date_ended)');
query1.parambyname('date_ended').asdatetime:= 1;
query1.ExecSQL;

I get the error : Type mismatched if I use "key" or
Invalid use of keyword ,token:key
if I use KEY no quoted.
Please an help,
thank you in advance & regards,
Giovanni.




Back to top
Don Gollahon
Guest





PostPosted: Tue Apr 06, 2004 12:52 pm    Post subject: Re: Delete records from table1 where in table2 ... Reply with quote



"Giovanni Filippini" <filippinig (AT) ciaoweb (DOT) it> wrote

Quote:
Hello to the Group,
(Delphi_6 - Paradox).
I need to delete records in Table1 if any record in
table2 with same key has a date.
Unfortunately I have a field named 'key'.
Here my code :
( 'key' and 'kkk' are the key fields to match )

query1.sql.clear;
query1.sql.add('delete FROM "table1.db"');
query1.sql.add('WHERE "key" IN');
query1.sql.add('(SELECT kkk FROM "table2.db" where date_ended
:date_ended)');
query1.parambyname('date_ended').asdatetime:= 1;
query1.ExecSQL;

That should work. Another way would be:

query1.sql.clear;
query1.sql.add('delete FROM "table1.db" t1');
query1.sql.add('WHERE Exists ');
query1.sql.add('(SELECT kkk FROM "table2.db" t2 where date_ended >
''12/31/1899''');
query1.sql.add(' and t1."key" = t2.kkk');
query1.ExecSQL;

Since you are creating the query on the fly, it is better not to use
parameters. Just fill-in the values.

Quote:

I get the error : Type mismatched if I use "key" or
Invalid use of keyword ,token:key
if I use KEY no quoted.

What are the field types of Key and KKK? Are they both integers?

Quote:
Please an help,
thank you in advance & regards,
Giovanni.



--

Don Gollahon
[email]gollahon (AT) geneseo (DOT) net[/email]



Back to top
Giovanni Filippini
Guest





PostPosted: Tue Apr 06, 2004 2:10 pm    Post subject: Re: Delete records from table1 where in table2 ... Reply with quote



Don,
thanks for your reply,
I get 'type mismatch' again,

kkk is 'autoinc'
key is integer.
Regards, Giovanni.



Back to top
Don Gollahon
Guest





PostPosted: Tue Apr 06, 2004 3:05 pm    Post subject: Re: Delete records from table1 where in table2 ... Reply with quote


"Giovanni Filippini" <filippinig (AT) ciaoweb (DOT) it> wrote

Quote:
Don,
thanks for your reply,
I get 'type mismatch' again,

kkk is 'autoinc'
key is integer.

Key must be Longint to match Autoinc.

Quote:
Regards, Giovanni.



--

Don Gollahon
[email]gollahon (AT) geneseo (DOT) net[/email]



Back to top
Giovanni Filippini
Guest





PostPosted: Wed Apr 07, 2004 10:04 am    Post subject: Re: Delete records from table1 where in table2 ... Reply with quote

thank you very much, Don,
regards, Giovanni.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) 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.