Try something like this: 'white-space: normal; max-width: 150pt;' AS 'td/@STYLE '. Use the appropriate width and units.
Sql server email html table column wrap
Hi,
We are sending emails using sql server db mail.
User would like to see 'Security Name' column data to be wrapped. Below code is not working. Please suggest what to do. forum is not letting me to add with trs and tds. So, I removed the part that generates table.
DECLARE @tmpTable AS TABLE
(
ReportID int NULL,
CUSIP varchar(20) NULL,
SecurityName varchar(100) NULL,
SubIssueName varchar(50) NULL,
Symbol varchar(10) NULL,
DepositDate date NULL,
SharesReceived decimal(18,6) NULL,
SharesTotalValue decimal(18,6) NULL,
SecuritiesCustodianName varchar(100) NULL,
SecuritiesCustodianID int NULL,
PropertyID BIGINT NULL,
Type_ID nvarchar(50) NULL
)
INSERT INTO @tmpTable
SELECT 596777, '455434209', '1111111111111 xxxxxxxxx INDIANAPOLIS POWER & LIGHT CO ZZZZZZZ ZZZZ',
'SubIssue Name', 'SymbolPK', '2017-01-13', 11.370000, 799.879500,
'Memphis POWER & LIGHT CO', 4, 50025220,'PENENDGEB'
DECLARE @tableHTML nvarchar(max)
, @tableHTMLFailures nvarchar(max)
, @executionDate DateTime
, @subjectLine varchar(250)
, @sendToAddress varchar(100)
, @ccAddress varchar(100)
, @FromEmailAddress varchar(100);
SET @subjectLine = '- XXX Demo';
SET @tableHTML =
CAST ( (SELECT td = ReportID, '',
td = PropertyID, '',
--'word-wrap:break-word' AS 'td/@class', td = SecurityName, '',
'white-space:normal' AS 'td/@style',td= SecurityName,'' ,
td = Cusip, '',
td = SharesReceived, '',
td = FORMAT(SharesTotalValue, 'C', 'en-us'), '',
td = DepositDate, '',
td = SecuritiesCustodianName, '',
td = Type_ID, ''
-- td = FORMAT(TransactionAmount, 'C', 'en-us'), ''
FROM @tmpTable
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
-- email part here
Thank You
Developer technologies | Transact-SQL
Developer technologies | ASP.NET | Other
3 answers
Sort by: Most helpful
-
-
Erland Sommarskog 121.8K Reputation points MVP Volunteer Moderator
2021-06-11T07:10:38.807+00:00 Not sure that you are in the right forum... You may be using SQL, but you producing HTML and you are battling with a mail reader.
Anyway, add a PRINT of your HTML and copy and save it to an .HTML file and open it a browser, so you see that it renders as you want.
If it still does not display well in the mail reader - well, that may be an uphill battle. I recall that I worked with something like this. I produced HTML from my stored procedure, and it displayed as I wanted in the browser, but some of the fancy effect I had added did not display in Outlook.
-
Yijing Sun-MSFT 7,096 Reputation points
2021-06-11T09:39:08.923+00:00 Hi @Spunny ,
As far as I think,you could check Firebug,this may override your specified line break behaviour. You may could use this:table { table-layout:fixed; width:100%; }
More details,you could refer to below article:
https://stackoverflow.com/questions/1258416/word-wrap-in-an-html-tableBest regards,
Yijing Sun
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.