T-SQL Data Type & sp_send_dbmail

Hi !

I'm having a little issue with sp_send_dbmail and datatype

I've done a trigger that send me an email each time a row is insterted in a table. The email include the inserted data. That's working well.

The table I use contain a column named "subject" and another one name "notes"
My Database collation is : Latin1_General_CI_AS
"Subject" column datatype is : nvarchar(255)
"Notes" column datatype is : ntext

Here's my trigger code:

USE [MyDatabase]


ALTER TRIGGER [dbo].[tr_send_email_when_cancelled]
ON [dbo].[tasks]
      IF EXISTS (SELECT NULL FROM INSERTED WHERE CategoryID = '7F1335C8-5850-4C49-92F4-6D2321B79138')

            DECLARE @UserID Uniqueidentifier = (SELECT ProjectID FROM INSERTED)
            DECLARE @BodyTXT nvarchar(max) = dbo.fnGetHRAnalysis(@UserID,null)
            DECLARE @SubjectTXT VARCHAR(255) = (SELECT subject FROM INSERTED)

            EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'MyProfile',
        @recipients = 'alias@mydomain.ca',
        @body_format = 'HTML',
        @body = @BodyTXT,
        @subject = @SubjectTXT;

My problem is that each time there is an accented caracter in the "Subject" field (é à è...), I get the email with a scrambled subject like this in outlook :

email sent with subject without accent are printed correctly in outlook.

Can someone tell me what I did wrong and how to fix it ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This link should help: Accent Removal

There are a few functions on there that can help you resolve this problem. I have used them before quite a bit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rubicon2009Author Commented:
Msg 156, Level 15, State 1, Procedure tr_send_email_when_cancelled, Line 19
Incorrect syntax near the keyword 'COLLATE'.

DECLARE @SubjectTXT NVARCHAR(255) = 'Un quart de travail à été annulé : ' + (SELECT subject FROM INSERTED)

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyProfile',
@recipients = alias@domain.ca',
@body_format = 'HTML',
@body = @BodyTXT,
Sorry about that, ignore my initial, I changed it now, if you copy the code from the link and then invoke the function.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Rubicon2009Author Commented:
The solution provided is great but I'll like to know why this is happening. Do you have any ideas ?

I know for sure that @subject used into dbmail is expecting a nvarchar(255) datatype.
Is it possible that my own variable containg the subject is sending more bytes and it is being truncated so the email client can't read it correctly ?
I'm not too certain why this is happening but I'll do some investigation and some tests on my system.

I don't think that datalength is the issue, but just try changing datatype to varchar(max) and see if that works ok.
Rubicon2009Author Commented:
Okay Keep me posted :)

I'll give point for the REPLACE solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.