You are on page 1of 6

SQL Word

Documents are the universal truth across organizations of all sizes.


Proposals, contracts, invoices, and compliance documents are all part of business
operations. Enterprises use approved document templates for each of these
document types. Whereas, databases hold the data that goes into these document
templates for business documents production.
Re-key data into templates wastes time and resources. Hence, businesses look to
automate document creation from SQL files. An ideal solution would populate
the SQL Server/Oracle/MySQL data into Word/PDF document templates for Docx
and PDF documents generation. It also should allow bulk/on-demand document
creation. Smartly choosing the right approach can save you thousands of dollars and
countless hours.

SQL Server WORD Population

SQL to Word with EDocGen

It is designed for business users to generate business documents without IT support.


Generate documents from SQL Server in a simple 2-step process.

1. Connect to your database from the system.


2. Generate documents using custom SQL queries.
3. Optionally, you can choose to send generated documents to individual recipients.

Step1: Connect to the database


In the connection screen, select the SQL server from the drop-down. Then enter the
connection URL in the "username@hostname[:port]/DatabaseName" format and the
password to access database.
In the query, you can use native SELECT statements. Below are the sample
MSWord template and the associated query for populating it. The system populates
the table, image, and dynamic text fields in the template from database fields.
SELECT
invoice.inv_no,
`logo`,
`date`,
`trms_pymnt`,
`po_ref`,
`name`,
`address`,
`contact`,
`Email`,
`Phone`,
`myhtml`,
para,
CONCAT(
'[',
GROUP_CONCAT(
CONCAT(
'{"amnt":"',
amnt,
'", "descrptn":"',
descrptn,
'"}'
)
),
']'
) IT
FROM
`invoice`,
`inv_item`
WHERE
invoice.inv_no = inv_item.inv_no
Group BY
invoice.inv_no;

The system supports all types of queries including SQL joins.


Business documents are complex. Most of them would need the population of tables,
images, HTML, Blob, etc. The system supports all these scenarios.
Tables

The system supports the creation of tables, loops, and lists from DB data. You can
also create nested tables up to 6 levels. For nested tables, fetching data in JSON
and XML formats through SQL queries is advisable. Take the example of "Order
table".
Sales Order Order Status

12345 5

-- --

Below is the query that populates this table. It fetches the data in XML format.

SELECT Cust.CustomerID,
OrderHeader.SalesOrderID,
OrderHeader.Status,
Cust.CustomerName
FROM Sales.Customer Cust, Sales.SalesOrderHeader OrderHeader
WHERE Cust.CustomerID = OrderHeader.CustomerID
ORDER BY Cust.CustomerID
FOR XML AUTO, ELEMENTS

Similarly, the below query fetches the data in JSON format.

SELECT CustomerID,
CustomerName,
(SELECT SalesOrderID, Status
FROM salesOrderHeader AS D
WHERE H.CustomerID = D.CustomerID
FOR JSON PATH) AS D
FROM Customer AS H
FOR JSON PATH

You might also like