Forum Discussion
Moving Away from MS Access
Hi all,
to make this move easier for everyone, a lot of SQL from MS Access is a problem for non-skilled would-be devs out there - like myself.
So, have you ever considered using ChatGPT for moving ie Reports SQL from Access?
Here is a large Reports SQL converted by ChatGPT, if asked nicely 🙂
Used ChatGPT on many occasions, sometimes it's wrong, sometimes is 100% correct.
If you are not able to read the output code and verify that it looks reasonable, don't put it in production.
- AL2001Jul 06, 2023Copper Contributor
I can actually demonstrate this.
The Northwind Traders v1 template app has massive SQL for the Inventory list.Here is the SQL (as from Access):
SELECT Products.ID AS [Product ID], Products.[Product Name], Products.[Product Code], Nz([Quantity Purchased],0) AS [Qty Purchased], Nz([Quantity Sold],0) AS [Qty Sold], Nz([Quantity On Hold],0) AS [Qty On Hold], [Qty Purchased]-[Qty Sold] AS [Qty On Hand], [Qty Purchased]-[Qty Sold]-[Qty On Hold] AS [Qty Available], Nz([Quantity On Order],0) AS [Qty On Order], Nz([Quantity On Back Order],0) AS [Qty On Back Order], Products.[Reorder Level], Products.[Target Level], [Target Level]-[Current Level] AS [Qty Below Target Level], [Qty Available]+[Qty On Order]-[Qty On Back Order] AS [Current Level], IIf([Qty Below Target Level]>0,IIf([Qty Below Target Level]<[Minimum ReOrder Quantity],[Minimum Reorder Quantity],[Qty Below Target Level]),0) AS [Qty To Reorder] FROM ((((Products LEFT JOIN [Inventory Sold] ON Products.ID = [Inventory Sold].[Product ID]) LEFT JOIN [Inventory Purchased] ON Products.ID = [Inventory Purchased].[Product ID]) LEFT JOIN [Inventory On Hold] ON Products.ID = [Inventory On Hold].[Product ID]) LEFT JOIN [Inventory On Order] ON Products.ID = [Inventory On Order].[Product ID]) LEFT JOIN [Products On Back Order] ON Products.ID = [Products On Back Order].[Product ID]; SELECT [Inventory Transactions].[Product ID], Sum([Inventory Transactions].Quantity) AS [Quantity Sold] FROM [Inventory Transactions] WHERE ((([Inventory Transactions].[Transaction Type])=2)) GROUP BY [Inventory Transactions].[Product ID]; SELECT [Inventory Transactions].[Product ID], Sum([Inventory Transactions].Quantity) AS [Quantity Purchased] FROM [Inventory Transactions] WHERE ((([Inventory Transactions].[Transaction Type])=1)) GROUP BY [Inventory Transactions].[Product ID]; SELECT [Purchase Order Details].[Product ID] AS [Product ID], Sum([Purchase Order Details].Quantity) AS [Quantity On Order] FROM [Purchase Order Details] WHERE ((([Purchase Order Details].[Posted To Inventory])=False)) GROUP BY [Purchase Order Details].[Product ID]; SELECT [Inventory Transactions].[Product ID], Sum([Inventory Transactions].Quantity) AS [Quantity On Hold] FROM [Inventory Transactions] WHERE ((([Inventory Transactions].[Transaction Type])=3)) GROUP BY [Inventory Transactions].[Product ID]; SELECT [Order Details].[Product ID] AS [Product ID], Sum([Order Details].Quantity) AS [Quantity On Back Order] FROM [Order Details] WHERE ((([Order Details].[Status ID])=4)) GROUP BY [Order Details].[Product ID];This SQL is obviously valid only for the MS Access. It takes a significant skill to re-write this to a standard SQL.
What ChatGPT produced is this:
SELECT p1.ID AS ID, p1.Product_Name AS Name, COALESCE( (SELECT SUM(od.quantity) FROM order_details od WHERE p1.ID = od.product_id AND od.status_id = 4), 0) AS quantity_on_back_order, COALESCE( (SELECT SUM(it1.quantity) FROM inventory_transactions it1 WHERE p1.ID = it1.product_id AND it1.transaction_type = 1), 0) AS quantity_purchased, COALESCE( (SELECT SUM(it1.quantity) FROM inventory_transactions it1 WHERE p1.ID = it1.product_id AND it1.transaction_type = 2), 0) AS quantity_sold, COALESCE( (SELECT SUM(it1.quantity) FROM inventory_transactions it1 WHERE p1.ID = it1.product_id AND it1.transaction_type = 3), 0) AS quantity_on_hold, COALESCE( (SELECT SUM(po1.quantity) FROM purchase_order_details po1 WHERE p1.ID = po1.product_id AND po1.posted_to_inventory = 0), 0) AS quantity_on_order, p1.target_level AS target_level FROM products p1 GROUP BY p1.ID, p1.Product_Name, p1.target_level ORDER BY p1.ID;It is 100% accurate. Just look at the quality of this SQL. Amasing.
Of course, up to the user to test the iteration, because it IS the process to get it right.
LEFT join will never produce the same result tho.What I wanted to point out is there are significant tools on anyone's disposal, to move the Front End and the DB to a new technologies.
But if Access if your bread and butter, that is another matter. The "Powers to Be" do not know what's out there, to make an informed decision.
- bmercerJul 06, 2023Iron ContributorI would not call that a "massive" sql query, but the fact that ChatGPT can produce functional output is impressive.
The problem is, it does not ALWAYS produce functional output.
Sometimes it produces impossible code that can't run. And sometimes it produces code that works, but does not do what you expect.
And it's up to you, the person implementing the solution, to verify it really does what you think it should.
As a tool to speed up development and improve accuracy, ChatGPT is great. But blindly trusting its output in production is a bad idea, and telling people with limited understanding of the code to blindly trust whatever ChatGPT tells them is bad advice.- BrianB_WS1OJul 06, 2023Copper Contributor
@inda reminds me of using the macro recording tool in Excel or Word to write some VBA routine, and then adapting it for other use, such as running an automated step in Excel from an MS Access database. You still have to fix it up, but it does save a lot of typing to get you started.