MS Access inserts multiple lines

For a project, I want to use a query to insert multiple rows into a table. I found a few threads on how to do this, such as this one , that were really helpful, but I still can't figure out how to insert multiple lines.

The SQL code I currently have doesn't throw a syntax error, but it just doesn't insert any rows.

My table that I want to insert looks like this:

create table SYT_ABRDAT
(
    id integer primary key not null,
    beginper integer,
    eindper integer,
    periode text,
    groep bit
)

      

The query I'm currently using (I made it shorter):

insert into syt_abrdat (id, begindat, einddat, periode, groep) 
    select * 
    from
        (select top 1 
             "1" as id, "9999" as begindat, "9999" as einddat,
             "---" as periode, "1" as groep 
         from 
             onerow 
         union all
         select top 1 
             "2" as id, "9999" as begindat, "9999" as einddat,
             "XXX" as periode, "1" as groep 
         from 
             onerow
        )

      

Decision:

I added an empty row to the table onerow

instead of filling it with some data.

It's necessary

+3


source to share


1 answer


INSERT INTO syt_abrdat (id,begindat,einddat,periode,groep) 
SELECT * FROM 
   (SELECT TOP 1 1 AS id, 9999 AS begindat, 9999 as einddat, '---' as periode, 'WAAR' as groep FROM onerow UNION ALL
    SELECT TOP 1 2 AS id, 9999 AS begindat, 9999 as einddat, 'XXX' as periode, 'WAAR' as groep FROM onerow)

      

Comments:



  • Use single quotes for literal string values
  • Don't use quotes for literal numbers
  • the table onerow

    must contain at least 1 record
+3


source







All Articles