Formatting Issue with Query Result Using "sp_send_dbmail"

  • I'm using sp_send_dbmail to send the results of a query to my my users. No problems with that, but a little bit of a formatting issue. Not to be nitpicky, but the query result has 3 columns and the first column is WAY wider than the following two. Example below:

    COLUMN1 COLUMN2 COLUMN3

    The query result is in simple text format. Also, the query results for COLUMN1 are small - there is absolutely no need for COLUMN1 to be that large. Any body know how to shrink down the width of COLUMN1 so it's the same as the other 2 columns? Thanks in advance!

  • In your query, CAST the first field as a certain length and that should reduce the width it allocates in the email.

  • If you want to control the width of the data, then in the SELECT query that that sp_send_dbmail calls, cast the columns you are fetching to the desired width, (possibly renaming the column name if you are showing headers and want that name also to be a narrower width.) For example:

    SELECT CAST(Column1 as CHAR(4)) as Col1, Column2, Column3 FROM x

  • Thanks Andy!

  • Thanks Greg! Works great.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply