Link to home
Create AccountLog in
Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Avatar of jseneris
jseneris

Can't figure out Insert SQL command with subquery
Hi,

I'm trying to write an Insert statement in Access where the value the field is set to is determined by a subquery.  I have two tables, the target table, tblShiftDetails that has fields shiftId(integer) and Shift (datetime); and the other table is tblShift that has fields ShiftId (integer), ShiftStart and ShiftEnd.

What I want to do is:

update tblShiftDetails
set shiftId = (select ShiftId from tblShift where Shift between ShiftStart and shiftEnd)


I get an "Operation must use an updateable query" error.  

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]Guy Hengel [angelIII / a3]🇱🇺

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Patrick MatthewsPatrick Matthews🇺🇸

Hello jseneris,

There is a possibility that your subquery returns more than one record in tblShift for each record
in tblShiftDetails, which would be a big no-no.

Regards,

Patrick

I have found that many queries that I would LIKE to use as an update query will not allow me for the same reason.

My solution is to convert the query into a make table query, creating a temp table, then running the update using a second query and this new table.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.