Link to home
Start Free TrialLog in
Avatar of Shepwedd
Shepwedd

asked on

How do I reference a new line in sql for my database mail query?

Hi,

I have written the attached database mail query but I'm struggling to find the sql to reference a new line in my query. In the attached code I have tried '\n' but it doesn't seem to work. Can anyone help?
DECLARE @trust_subject NVARCHAR(100)
DECLARE @trust_message NVARCHAR(MAX)
SET @trust_subject = 'Trust System - Crucial Date Alert';
 
DECLARE  CursorTemplate CURSOR 
      FAST_FORWARD FOR       
      Select 
      'This is a reminder that the below crucial date is due exactly two months today:\n\nClient Name: ' + tt.ClientName + '\n\nMatter Number:' + tt.MatterNo + '\n\nPartner:' + tpl.PartnerDescription + '\n\nFee Exec:' + tfel.FeeExecDescription + '\n\nDue Date:' + CAST(cdtcd.DueDate as NVARCHAR) + '\n\nEvent:' + cdel.EventDescription
      From Trusts.Trusts tt INNER JOIN Trusts.PartnerLookup tpl ON tt.PartnerCode = tpl.PartnerCode INNER JOIN Trusts.FeeExecLookup tfel ON tt.FeeExecCode = tfel.FeeExecCode INNER JOIN CrucialDates.TrustCrucialDates cdtcd ON tt.TrustID = cdtcd.TrustID INNER JOIN CrucialDates.EventLookup cdel ON cdtcd.EventCode = cdel.EventCode
 
OPEN CursorTemplate
 
FETCH NEXT FROM CursorTemplate 
INTO      @trust_message
 
WHILE (@@FETCH_STATUS = 0)
BEGIN
	EXEC msdb.dbo.sp_send_dbmail
      @recipients = 'someone@somewhere.co.uk', 
      @body = @trust_message,
      @subject = @trust_subject
 
      FETCH NEXT FROM CursorTemplate 
      INTO      @trust_message
 
END
 
CLOSE CursorTemplate
DEALLOCATE CursorTemplate

Open in new window

Avatar of chapmandew
chapmandew
Flag of United States of America image

+ char(10) + char(13) + ...
SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the char(10) + char(13) didn't work?
char(10) + char(13) is not simple line break it inserts one free line.
char(13) + char(10) works as simple line break.