One of the more powerful roles that SQL Server 2005 Express plays is the ability to serve as a backend for Microsoft Office applications. Many members of the Microsoft Office Suite have close ties to SQL Server Express, making integration an easy task. In my last Express Essentials column"Excel Integrations" (InstantDoc ID 96444, ), we looked at integrating Excel 2007 with SQL Server Express. In this column you’ll see how you can take advantage of the close ties with Office 2007 to integrate Word 2007 with SQL Server Express for use with mail merge, form letters, labels, and envelopes.

As just about everyone knows Word’s ability to combine text and graphics make it an excellent tool for generating great looking letters and office documents such as orders and invoices. However, Word can fall short when you need to create mass mailings for large numbers of customers or employees (cut–and-pasting dozens or even hundreds of names and address gets old real fast). That’s where Word 2007’s SQL Server integration comes in handy. Word 2007’s tight integration with SQL Server enables you to create form letters and mailings that are driven by data in a SQL Server Express database. So rather than needing to cut-and-paste a couple of hundred different names and addresses, you can create a Word mail merge document that can generate customized mailings based on customer, employee, or any other data that’s stored in one of your SQL Server Express databases.

To create a Word 2007-SQL Server Express mail merge, open up Word 2007 and then click on the Mailings tab that you see on the Ribbon and select the Start Mail Merge option. This gives you the option to create a Word-database mail merge for Letters, E-mail messages, Envelopes, Labels, or a Directory. All of these selections have similar capabilities, but because each type is a bit different the exact steps will vary.

To create an Envelope Mail Merge, select the Envelopes option and click OK to display the Envelope document. Word’s default return address will be displayed. Next, click on Select Recipients, and then choose Use Existing List from the pop-up menu. This will display the Select Data Source dialog. To create a new mail merge, click the New Source button to start Office 2007’s Data Connection Wizard. From the data sources list select Microsoft SQL Server and click Next. In the Connect to Database Server dialog enter SQLEXPRESS for the server name prompt if you are connecting to a SQL Server Express instance on the local system. Then select Use Windows Authentication if you are using the SQL Server Express default authentication method. Click Next to display the Select Database and Table dialog. Use the upper dropdown to pick the database--in this example I’ll choose Northwind and then I’ll select Employees from the list of tables. Click Next and then finish to save the Data Source. Next, position the cursor on the letter document where you want the merged text to appear and then click the Insert Merge Field option. From the Insert Merge Field box, pick each database column that you want to appear on the envelope and click Insert. After choosing all of the fields go to the Ribbon and Click Start Mail Merge to run Mail Merge. After the mail merge has completed, you can use Word 2007’s print option to print the envelopes. Combining Word 2007 and SQL server Express can be a huge time saver when you want to merge SQL server Express’ database data with Word’s text and graphics.