Convert Code from Access (1 Viewer)

tucker61

Registered User.
Local time
Today, 00:05
Joined
Jan 13, 2008
Messages
324
I have the code below in a access query to update the JOb_ID fields that are blank,
This is approx 600,000 rows, and takes forever to run - i have to keep stopping the query.

What do i need to do to convert this, so i can run in SQL Server and not through access ?

Thanks in advance.

Code:
UPDATE tblQCIntake INNER JOIN tblQCIntakeDetail ON (tblQCIntake.Entered_By = tblQCIntakeDetail.Enterd_By) AND (tblQCIntake.Input_Date = tblQCIntakeDetail.Input_Date) SET tblQCIntakeDetail.Job_ID = [tblQCIntake].[Job_ID]
WHERE (((tblQCIntakeDetail.Job_ID) Is Null));
 

Josef P.

Well-known member
Local time
Today, 09:05
Joined
Feb 2, 2023
Messages
826
This is a job for ChatGPT & co. ;)

Instruction to ChatGPT:
Convert this access query to TSQL:
UPDATE tblQCIntake INNER JOIN tblQCIntakeDetail ON (tblQCIntake.Entered_By = tblQCIntakeDetail.Enterd_By) AND (tblQCIntake.Input_Date = tblQCIntakeDetail.Input_Date) SET tblQCIntakeDetail.Job_ID = [tblQCIntake].[Job_ID]
WHERE (((tblQCIntakeDetail.Job_ID) Is Null));
Result:
SQL:
UPDATE td
SET td.Job_ID = ti.Job_ID
FROM tblQCIntakeDetail td
INNER JOIN tblQCIntake ti
   ON td.Entered_By = ti.Entered_By
   AND td.Input_Date = ti.Input_Date
WHERE td.Job_ID IS NULL;

Check: TSQL code is created correctly.

Update syntax: https://learn.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql?view=sql-server-ver16
 
Last edited:

tucker61

Registered User.
Local time
Today, 00:05
Joined
Jan 13, 2008
Messages
324
This is a job for ChatGPT & co. ;)

Instruction to ChatGPT:

Result:
SQL:
UPDATE td
SET td.Job_ID = ti.Job_ID
FROM tblQCIntakeDetail td
INNER JOIN tblQCIntake ti
   ON td.Entered_By = ti.Entered_By
   AND td.Input_Date = ti.Input_Date
WHERE td.Job_ID IS NULL;

Check: TSQL code is created correctly.

Update syntax: https://learn.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql?view=sql-server-ver16
Perfect - Wish i had asked Hours ago - that took 10 seconds SQL Server

Never Used ChatGPT - Did not know it could convert code.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:05
Joined
Feb 28, 2001
Messages
27,186
Be aware that while it is possible to ask ChatGPT and get a decent-looking answer, it is ALSO possible that you will get back a wrong answer. We have had a few reports here of ChatGPT code that didn't work and would never work. Not saying to avoid ChatGPT. Just set yourself up for a test before committing to running your entire data set on something generated that way.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 08:05
Joined
Feb 19, 2013
Messages
16,612
there is also this resource here

link was sent to me by someone today

result was pretty much the same

Code:
UPDATE tblQCIntakeDetail
SET tblQCIntakeDetail.Job_ID = [tblQCIntake].[Job_ID]
FROM tblQCIntake
    INNER JOIN tblQCIntakeDetail ON (tblQCIntake.Entered_By = tblQCIntakeDetail.Enterd_By)
    AND (tblQCIntake.Input_Date = tblQCIntakeDetail.Input_Date)
WHERE (((tblQCIntakeDetail.Job_ID) Is Null))
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 08:05
Joined
Jul 9, 2003
Messages
16,282
Never Used ChatGPT - Did not know it could convert code.

I started a thread about Chat GPT, it might be of interest.

Not only can it generate code but it can also help you with blogging, writing letters, writing emails. I've even asked it to help me navigate the school system to get my grandson some extra help. This is the thread:-

 

Minty

AWF VIP
Local time
Today, 08:05
Joined
Jul 26, 2013
Messages
10,371
It's worth noting that the T-SQL version doesn't need the myriad of brackets that Access uses.

Large recordset update queries in particular are nearly always much better handled directly in SQL Server, I haven't been able to really fathom out why though, but assume its transcational logs/rollback issues?
 

sonic8

AWF VIP
Local time
Today, 09:05
Joined
Oct 27, 2015
Messages
998
It's worth noting that the T-SQL version doesn't need the myriad of brackets that Access uses.
Even Access itself doesn't need the myriad of brackets that the Access visual query designer is adding to the queries.

Large recordset update queries in particular are nearly always much better handled directly in SQL Server, I haven't been able to really fathom out why though, but assume its transcational logs/rollback issues?
A huge part of the performance problem with Access queries on linked ODBC tables is covered in my text Microsoft Access - ODBC Linked Tables – Mechanisms and Performance.
With update queries this might be aggravated by Access sending an update statement for every single row it wants to update instead of a single statement for all of them.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:05
Joined
Feb 19, 2002
Messages
43,275
I haven't been able to really fathom out why though, but assume its transcational logs/rollback issues?
You will see the difference if you run an Access query vs a passthrough query. Notice how Access asks if you want to add x records, etc but the pass through does not. While all my forms are bound and the majority of my queries are Access querydefs, some action queries are faster as passthrough queries. I have some temp tables that hold data imported from an application and we are not allowed to link directly to the tables so I have no choice but to import the data every morning before the day starts. In this case, I use truncate to get rid of the data and then append to copy the .csv into a table for us to use that day.
 

Minty

AWF VIP
Local time
Today, 08:05
Joined
Jul 26, 2013
Messages
10,371
Because we mainly use Azure SQL backends, almost all our action queries are pass-throughs.
We also use back-end temporary tables to join to when running complex queries to increase response speed on big tables (Millions of records) .
It makes a significant difference.
 

Users who are viewing this thread

Top Bottom