Is there any way to create multiple insert statements in a ms-access query? -
i using ms access 2003. want run lot of insert sql statements in called 'query' in ms access. there easy(or indeed way) it?
yes , no.
you can't do:
insert foo (c1, c2, c3) values ("v1a", "v2a", "v3a"), ("v1b", "v2b", "v3b"), ("v1c", "v2c", "v3c")
but can do
insert foo (c1, c2, c3) select (v1, v2, v3) bar
what if don't have data in table? well, craft select statement composed of lot of unions of selects hard coded results.
insert foo (f1, f2, f3) select * (select top 1 "b1a" f1, "b2a" f2, "b3a" f3 onerow union select top 1 "b1b" f1, "b2b" f2, "b3b" f3 onerow union select top 1 "b1c" f1, "b2c" f2, "b3c" f3 onerow)
note: have include form of dummy table (e.g., onerow) fool access allowing union (it must have @ least 1 row in it), , need "top 1" ensure don't repeats table more 1 row
but again, easier 3 separate insert statements, if building things in loop (unless of course cost of doing inserts greater cost of time code it).
Comments
Post a Comment