
Photo by Author | Chat GPT
Hidden cost of reporting of normal SQL
Data teams in organizations face the challenge of once -to -be: stakeholders need regular reports, but manual SQL reporting uses valuable time that can be spent on analysis. This process remains permanently regardless of the size of the company-connect to the data base, process questions, format the results, and divide the results to the decision makers.
Data professionals handle reporting tasks that do not require advanced statistics knowledge or domain skills, yet they use important times through repeated implementation of the same questions and formatting procedures.
This workflow solves the basic performance problem: transforming one -time setup directly into stakeholder inboxes into the ongoing automatic delivery of professional reports.
Solution: a 4-nood automatic reporting pipeline
The formation of our former N8N research, this workflow is dealt with by a different automation challenge: scheduled SQL reporting. Although our first tutorial focuses on data quality analysis, it shows how N8N handles the database integration, repeatedly -running schedules and email distribution.
Unlike writing standstone -stone script for reporting, N8N workflows are visual, reusable and easy to edit. You can connect the database, perform changes, analyze, and provide results – all this without switching to different tools or environments. Each workflow contains “nodes” that represent different steps, which are connected to each other to create an automated pipeline.
Our automated SQL reporter consists of four connected nodes that convert manual reporting into a hand -off process.
- Schedule trigger – Every Monday runs 9am in the morning
- Postgrass Ql Node – performs sales inquiry against the database
- Code node – converts raw data to Formated HTML report
- Send the email node – provides a professional report to stakeholders
Construction of Workflow: Phase -implemented
Provisions
Step 1: Set up your postgrass QL Database
We will create a realistic sales database using the soup base for this tutorial. The soup base is a cloud -based postgrass QL platform that provides built -in APIS and verification -organized databases. Although it uses a soup base for tutorial convenience, the N8N workflow is linked to any postgrass SQL database, which includes AWS RDS, Google Cloud SQL, or existing database infrastructure in your organization.
Create soup base account:
- See supabase.com And sign up in free
- Create a new project – Choose any name and region
- Wait for the setup – Database supplies take About about 2 minutes
- See your contact details Settings> Database Page (or the “Contact” button on the main page)
Load sample data:
Go to the SPB Editor in Soup Base and run this setup script to create our sales database table and settled them with sample data:
-- Create employees table
CREATE TABLE employees (
emp_id SERIAL PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department VARCHAR(50)
);
-- Create sales table
CREATE TABLE sales (
sale_id SERIAL PRIMARY KEY,
emp_id INTEGER REFERENCES employees(emp_id),
sale_amount DECIMAL(10,2),
sale_date DATE
);
-- Insert sample employees
INSERT INTO employees (first_name, last_name, department) VALUES
('Mike', 'Johnson', 'Sales'),
('John', 'Doe', 'Sales'),
('Tom', 'Wilson', 'Sales'),
('Sarah', 'Chen', 'Marketing');
-- Insert recent sales data
INSERT INTO sales (emp_id, sale_amount, sale_date) VALUES
(1, 2500.00, CURRENT_DATE - 2),
(1, 1550.00, CURRENT_DATE - 5),
(2, 890.00, CURRENT_DATE - 1),
(2, 1500.00, CURRENT_DATE - 4),
(3, 3200.00, CURRENT_DATE - 3),
(4, 1200.00, CURRENT_DATE - 6);
Paste this entire script into the SQL Editor and click the “Run” button in the bottom right corner. You have “success. No rows have returned” confirm that your tables and sample figures are successfully created.
Test your contacts:
Within the same SQL editor, run a fresh inquiry to confirm each work: SELECT COUNT(*) FROM employees;
You should see 4 employees in the results.
Step 2: Configure Gmail to Automatically Send
Enable the App Password:
- Turn on 2 step verification In your Google Account Settings
- Prepare the App’s Password – Go to Security> App Password
- Choose “mail” and “other” – its name “N8N Reporting”
- 16-Copy Copy Password – You will need it for N8N
Step 3: Import and configure the workflow
Import Template:
- Download the Work File file
- Open n8n And click “Import from the file”.
- Select the downloaded file – Four nodes appear automatically
- Save the workflow As a “automatic SQL reporting”
Imported workflow contains all four connected nodes, all of which are already formed by SQL and formatting code.
Configure Database Connection:
- Click on Post Grace SQL Node
- Get your contact details From the soup base by clicking the “Connect” button on your main page. N8N Integration LP, Use the “Transaction Polar” connection string as it is better for automated workflows:
- Create a new certificate With the details of your Sopas:
- Host: (your project) .supabase.com
- Database: Postgrade
- User: Postgrades …..
- Password: (from Soup Base Settings)
- Port: 6543
- SSL: Make it worth
- Test connection – You should see a message of green success
Configure email settings:
- Click the E -mail Node
- Create SMTP Certificate:
- Host: smtp.gmail.com
- Port: 587
- User: You- Email@gmail.com
- Password: (your app password)
- Safe: Enable Start TL
- Update the recipient In the field of “email”
This is! Analysis logic automatically adapts to various database schemes, table names and data types.
Step 4: Tests and deployed
- Click on “Workflow wear practical clothes” In the toolbar
- See every node Get green as it acts
- Check your email – You should receive a formed report
- Toggle on “Active” Monday morning to enable automation
Once the setup is completed, you will receive automatic weekly reports without any manual intervention.
Understanding your automatic report
Here’s what your stakeholders get every Monday.
E -mail article: 📊 Weekly sales report – June 27, 2025
Report Material:
- Clean the HTML Table With appropriate styles and borders
- Summary Statistics SQL results are automatically calculated
- Professional formatting Is suitable for executive stakeholders
- Timstamp and metad data For Audit Trails
Here looks like a final report:
The workflow automatically handles all complex formatting and calculations behind this professional output. Consider how the report includes appropriate currency formatting, calculated average, and clean table style. All of this is directly produced by the consequences of the raw SQL without any manual intervention. The email arrives with the time stamp, making it easier to track the reporting period to the stakeholders and maintain the audit trails for the decision -making process.
Technical deep divers: understanding of implementation
Schedule Trigger Configure:
The workflow runs every Monday at 9:00 am using N8N’s interval schedule. It ensures that reports arrive before the weekly team meetings.
SQL Question Logic:
Included in the postgrade QL Node, a sophisticated inquiry is implemented with filtering, collecting and appropriate numerical formatting. It automatically:
- Employee and Cell Tables for full records
- Filters data up to 7 days using
CURRENT_DATE - INTERVAL '7 days'
- Total sales, revenue and each person’s average
- Results of revenue for business preference
HTML Generation Logic:
The code node converts SQL results into professional HTML using Javascript. This repetitions through the results of the queries, makes the styled HTML tables with permanent formatting, calculates summary statistics, and adds professional contacts such as emojis and time stamp.
E -mail supply:
Send email node uses Gmail’s SMTP service with proper verification and HTML rendering support.
Testing with different scenarios
To see how the workflow handles different data patterns, try these edits:
- A period of different timeChange
INTERVAL '7 days'
toINTERVAL '30 days'
For monthly reports - Department filtering: Add
WHERE e.department="Sales"
For team reports - Different matrix: Edit the selected clause to add product category or customer segments
Based on your business needs, you can determine the next steps: Weekly reports work well for operational teams, according to monthly reports, strategic planning, quarter reports help executive dashboards, and real -time monitoring in daily reports. The workflow automatically adapts to any SQL structure, which allows you to quickly make multiple reporting pipelines for different stakeholders.
Next steps
1. Multi Database Support
Replace the Post Grace SQL Node with SQL, SQL server, or any supported database. Workflow logic remains the same while connecting to different data sources. This flexibility makes the text valuable in piles of diverse technology.
2. Advanced scheduling
Edit the scheduled trigger for different frequencies. Six daily reports for operational matrix, monthly reports for strategic planning, or quarterly reports for board meetings. Each schedule can target various recipient groups with content.
3. Better formatting
Chart. Extend the code node to include charts and concepts using JS, the threshold of performance -based conditional formatting, or executive summary with key insights. HTML output supports rich formatting and embedded graphics.
4. The multi -dimensional partition
Add logic to send different reports to different stakeholders. Sales managers receive individual team reports, executives get high levels of high levels, and finance teams receive a revenue -based matrix. This target approach ensures that every audience gets relevant information.
Conclusion
This automatic SQL reporting workflow shows how N8N data eliminates the difference between science skills and operational performance. By combining database integration, schedules, and email automation, you can eliminate routine reporting tasks while providing professional results to stakeholders.
The workflow modular design makes it especially valuable to data teams handling numerous reporting requirements. You can create a copy of different database work workflowers, edit SQL questions for different matrix, and adjust formatting for different audiences. All this without writing a custom script or management of server infrastructure.
Unlike traditional ETL tools that require a wider configuration, N8N’s visual interface makes complex data work flu accessible to both members of the technical and non -technical team. Your SQL skills are the main value, while N8N automation handles infrastructure, scheduling reliability, and delivery method.
Most importantly, this approach is in line with your organization’s needs. Start with simple weekly reports, then extend to add data concepts, multi -database questions, or integration with a business intelligence platform. The foundation you make today becomes an automated reporting infrastructure that supports your team’s development tomorrow.
Born in India and brought up in Japan, Vinod Data brings a global context of science and machine learning education. It eliminates the difference between emerging AI technologies and practical implementation for working professionals. Winode is focused on complex titles such as agent AI, performance correction, and AI engineering -learn learning accessories. He focuses on implementing the implementation of practical machine learning and direct sessions and personal guidance and guidance of data professionals.