In this article, we will see how to handle images with AI. Sometimes we need to import the text from images into SQL Server. In this article, we will use ChatGPT to convert text from images into text.
If you want to know more about ChatGPT, you can read my previous article: ChatGPT in SQL Server - Practical examples
Getting started
First, go to ChatGPT. If you do not have an account, create one.
I will ask ChatGPT if it can OCR some images.
Handle images with ChatGPT
Let’s try to read the text of the images with ChatGPT. You can drag and drop your image or use the Upload files icon.
Me: Please read the text of this image.
ChatGPT: The text in the image reads: "ROAD CLOSED."
Insert the text from the image into a table
Daniel: I have the following table:
CREATE TABLE image ( id INT, description VARCHAR(8000) );
Can you create the code to insert the previous picture's text into the table?
ChatGPT:
To insert the text "ROAD CLOSED" from the image into the image
table, you can use the following SQL query:
This query assumes you're inserting the first record (id = 1) into the table. Let me know if you need any adjustments!
How does the OCR handle images with Bard?
Me: How do you read the text from images?
ChatGPT:
I use Optical Character Recognition (OCR) technology to read and extract text from images. OCR scans the image for patterns that resemble letters, numbers, or symbols and converts them into readable text. When you upload an image with text, I can analyze it and provide you with the content of the image by recognizing these patterns.
If you'd like, I can also help you extract text from other images you might have. Just let me know!
Test how Bard handles images of a milk box
We will try to read the text on a box of milk.

Me: Can you do OCR to the text of this image?
ChatGPT:
The text from the image is:
- "REAL MILK great taste"
- "HORIZON ORGANIC"
- "ORGANIC WHOLE MILK"
- "VITAMIN D • UHT"
- "8 FL OZ (236 mL)"
- "USDA ORGANIC"
This is the text displayed on the milk carton. Let me know if you'd like to extract more information or need anything else!
How to create a SQL Server table to insert images from ChatGPT
Previously, we showed how to convert the text in images into text. Now, we need a table in SQL Server to store the data. I am assuming that you have SQL Server installed.
First, create the table:
Me: Generate the T-SQL code to create a table named comments with the columns id of type int with autonumeric columns (numbers generated automatically with the identity property) and the column description of type varchar(max)
ChatGPT:
Here is the T-SQL code to create the comments
table with the specified columns:
- The
id
column is of typeINT
and is set to automatically generate numbers starting from 1, incrementing by 1, thanks to theIDENTITY(1,1)
property. - The
description
column is of typeVARCHAR(MAX)
to allow variable-length strings of any size.
Handle handwritten images in SQL Server with AI
Me: Can you do OCR to the text of this image and generate the T-SQL code to insert the text into the comments table previously created?
ChatGPT:
The text extracted from the image is:
- "We Start With Good"
- "Because all businesses should be doing something good."
Here is the T-SQL code to insert this text into the comments
table:
This query inserts the text as a single row into the comments
table, with the id
column automatically generated.
Me: I am impressed. The OCR could read handwritten text easily.
Insert Data from a chart into a table
Me: I have the following chart.
Please insert the coordinates x and y in the following table based on the image attached:
CREATE TABLE Coordinates ( id INT IDENTITY(1,1) PRIMARY KEY, x INT, y INT );
ChatGPT:
Based on the scatter plot, the coordinates (x, y) extracted are:
(4, 2)
(5, 3)
(6, 4)
(7, 5)
(8, 8)
You can use these coordinates to populate the table. Here's the SQL statement to insert the values into your table:
Me: Unfortunately, ChatGPT has some limitations in extracting values from an X, Y chart. It could not do it. This may change in the future.
Extracting values from images into T-SQL
Me: I have the following picture of the table:
Please create the T-SQL code to create the table with the data named dbo.salesreason.
ChatGPT:
To create the table dbo.salesreason
based on the data provided in the image, you can use the following T-SQL code:
Handle chart images with AI
Now, I will try to get information from the charts
Me: Can you explain to me what this chart means?
ChatGPT:
Provide an analysis of the chart with AI
Me: Based on the chart, do you think the price will increase or decrease this year?
ChatGPT:
Based on the chart you've provided, Bitcoin's price has been on a general upward trend over the last year, with some fluctuations along the way. There has been a noticeable rise, particularly in the recent months, and the chart shows a strong upward trajectory, especially after the dip around mid-2024.
However, predicting the future direction of Bitcoin's price is difficult because the cryptocurrency market is highly volatile, influenced by various factors like market sentiment, global events, regulatory changes, and technological advancements.
Some key observations from the chart:
- Current growth: The price is still relatively high compared to earlier periods, which might suggest continued bullish sentiment.
- Volatility: The chart also shows significant fluctuations, suggesting that the price could experience ups and downs, even within an overall increasing trend.
- Market sentiment: If the current momentum continues, with positive news around adoption or institutional investments, the price could continue to rise. However, any regulatory changes or adverse news could cause the price to dip.
Given this, while the trend seems positive, there is a significant level of uncertainty. If you are considering investing or making decisions based on Bitcoin's price, it might be wise to proceed cautiously and stay updated on market news.
Would you like more insights or help with any specific analysis regarding Bitcoin's price?
Store the data from the chart in a table
Me: Please store the price, marketcap, Volume, FDV, and Total supply from the previous chart into this table:
CREATE TABLE TradingData ( Id INT IDENTITY(1,1) PRIMARY KEY, Price DECIMAL(18, 8) NOT NULL, MarketCap DECIMAL(18, 2) NOT NULL, Volume DECIMAL(18, 2) NOT NULL, FDV DECIMAL(18, 2) NOT NULL, TotalSupply DECIMAL(18, 2) NOT NULL, Timestamp DATETIME NOT NULL DEFAULT GETDATE() );
ChatGPT:
Here is the T-SQL code to insert the data into the TradingData
table:
This code will insert the values for Price, MarketCap, Volume, FDV, and TotalSupply into the TradingData
table.
Let me know if you need any more adjustments!
Conclusion about the handled images in the AI article
Now the AI is providing not only OCR features to import text from images into SQL Server. Also, the AI can understand charts and do data analysis. AI is simplifying our job of doing data analysis, and soon, we will only need to ask the AI to do our job, and we will only need to organize the information.