-1

Hey there I have a simple EmailTemplate table with three columns:

TemplateName
EmailSubject
EmailContent

I have a client that wants to review all the templates and I'd like to put them into a word document, 1 per page, in the order they are above e.g.

-------------- page 1 --------------

[[TemplateName]]

[[EmailSubject]]

[[EmailContent]]
...
...
...
[[EmailContent]]

-------------- page 2 --------------

[[TemplateName]]

[[EmailSubject]]

[[EmailContent]]
...
...
...
[[EmailContent]]

Does anyone one know of an easy way to do this from SQL Server Management Studio?

Cheers Rob

Rob
  • 10,004
  • 5
  • 61
  • 91
  • Isn't SSMS just for querying for data and running traces and such or did they add export options of some sort? – Roman Feb 02 '13 at 01:41

2 Answers2

1

Word has a mail merge function that can be used with csv data, I'd recommend that over any attempt to build the entire thing in sql.

Kevin Dahl
  • 752
  • 5
  • 11
  • I started down this path and realised that I can't just jump on, use the mail merge wizard and off I go as the Mail Merge wizard is geared for address fields, so I'd then have to go down the path of setting up custom fields etc which is more effort than I want to invest in this process/client. – Rob Feb 02 '13 at 06:24
0

I did some more searching, lot's of code solutions but nothing out-of-the-box in SSMS so I did some more fiddling and here's what I did to achieve this:

  1. Set the query output to text
  2. Set the Query -> Query Options -> Text to: no headings and Delimeter | (so it's easy to remove)
  3. Added formatting to the query with Tabs CHAR(9) and Line Breaks CHAR(10) as follows:

    SELECT 'Template Name:' + CHAR(9) + CHAR(9) + Name + CHAR(10) + CHAR(10), 'Email Subject:' + CHAR(9) + CHAR(9) + TemplateSubject + CHAR(10) + CHAR(10) + CHAR(10), 'Contents:' + CHAR(10) + CHAR(10), TemplateContent + CHAR(10) + CHAR(10) + CHAR(10) + CHAR(10) + '------------------------------------' FROM dbo.EmailTemplate

I just copy/paste this contents into Word and then went through and converted the dashed line "----" to page breaks and sent it off to the client to review.

Rob
  • 10,004
  • 5
  • 61
  • 91