Page 1 of 1
Inserting different field into different tables
Posted: Mon Aug 06, 2012 4:52 am
by pidobearBUSsb9q
HI
THANks in Advance for helping
i am trying to insert into different tables into a database.
how to i change the SQL statement on it so that field 1 goes into column 1 for any table and when the field is empty it just leave it blank?
put "INSERT INTO VIP
(Name,Age,Job) " & \
merge
("VALUES ('[[Ftname]]', '[[Ftage]]', '[[Ftjob]]')") into tCmd
Cheers

Re: Inserting different field into different tables
Posted: Mon Aug 06, 2012 11:49 am
by Klaus
I am not an SQL expert, but I doubt that this is possible wothout 3 different SQL statements.
Re: Inserting different field into different tables
Posted: Sat Aug 18, 2012 12:59 am
by phaworth
I don't have your schema in front of me but off the top of my head, I'd say there's a problem with its design if you have multiple tables with the same data in them.
However, if you want to do this and you you are using SQLite, take a look at triggers. They allow you to define auxiliary actions when an INSERT, DELETE, or UPDATE happens on a table. In this case, you could define a trigger on the VIP table to execute when rows are inserted into it and request that the same data be inserted into the other tables you mentioned.
Pete
Re: Inserting different field into different tables
Posted: Sat Aug 18, 2012 5:46 pm
by Adrian
Could you give us some more detail about ehat you are wanting to achieve? I am not sure what you are trying to do with the merge statement, where one would expect "values".
If you build up the SQL statement string along the lines of
Put "insert into table (col1, col2) values('" & the text of field1 & "','" & the text of field2 & "')" into tSQL
(noting the single quotes within the double quotes)
then if a field is blank, the SQL would have two signel quotes for the column value, which is fine. E.g.
insert into table (col1,col2) values('abc','')
But let us know some more of what you are trying to do.
Cheers,
Adrian