 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Giovanni Filippini Guest
|
Posted: Tue Apr 06, 2004 7:18 am Post subject: Delete records from table1 where in table2 ... |
|
|
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
|
Posted: Tue Apr 06, 2004 12:52 pm Post subject: Re: Delete records from table1 where in table2 ... |
|
|
"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
|
Posted: Tue Apr 06, 2004 2:10 pm Post subject: Re: Delete records from table1 where in table2 ... |
|
|
Don,
thanks for your reply,
I get 'type mismatch' again,
kkk is 'autoinc'
key is integer.
Regards, Giovanni.
|
|
| Back to top |
|
 |
Don Gollahon Guest
|
Posted: Tue Apr 06, 2004 3:05 pm Post subject: Re: Delete records from table1 where in table2 ... |
|
|
"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
|
Posted: Wed Apr 07, 2004 10:04 am Post subject: Re: Delete records from table1 where in table2 ... |
|
|
thank you very much, Don,
regards, Giovanni.
|
|
| Back to top |
|
 |
|
|
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
|
|