INSERT with Random SELECT

Asked

Viewed 136 times

0

I have a table with several information and another empty.

I need to do an INSERT in this empty table with only one information from the other table, but SELECT has to be random.

I am using the following line in VBA:

db.Execute "INSERT INTO tbl_Sorteio SELECT TOP 1 RE, Name_Employee, Case_Number, [Date], [Time], Supervisor, Comment, Client ORDER BY Rnd(Case_Number)"

However I got the following error message:

erro VBA

Remembering, I’m using Access 2013.

  • Good morning caique, how so select random? tried to put variables in select?

  • Tried : ... order by Rnd"

  • Luiz, in the above case there was no FROM table in SELECT, but it is not 100%. The ORDER BY Rnd(Case_number) server to take a random number from the select table and insert it into the draw table. However I need to define in WHERE a range of dates, but it is not working. I do not know if it is Rnd() that does not work with WHERE or some other problem.

  • SELECT random? What do you mean?? In your query missing a FROM specifying the table where you are going to get the information.

  • @caiquelcn, managed to walk with the problem? the answer helped??

1 answer

2

I added the clause FROM that was missing and I started to filter the Case_Number instead of ordering the result by it; see if the command below solves:

db.Execute "INSERT INTO tbl_Sorteio SELECT TOP 1 RE, Name_Employee, Case_Number, [Date], [Time], Supervisor, Comment, Client FROM tbl_Sorteio WHERE Case_Number = Rnd(Case_Number)"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.