I am using 2 SQL Servers, 1 is a Production Server and 2 Live database server. I use to insert records in Server 1 and while inserting through VB code i generate an email that gets the data to Server 2 and inserts values there too. Now the problem is when Outlook at Server 2 gets the mail and try processing the mail from SQL Mail feature it gives error. When I use that statement and try to debug and check the hex value at DOS prompt the line where the error was given, contains line feed and caradge return, and that makes SQL Server 2 not to recognize the Query properly. Is there any feature/solution to overcome this problem.
Are you using xp_readmail to read the message? @message is text datatype, not varchar, so make sure you are not just truncating the message at the length of your declared @message variable (and it just happens to end @ CRLF.)
0
moazzam1574Author Commented:
Hi,
Well BillAn1, I am trying to use the replace function, I tried it last night, but somehow, it doesnt seem to work. Still trying. :). And yes Kselvia I am using xp_readmail, but how can I check/change the datatype of text that is in the message body. Can we apply this replace function to replace what we want in the text for xp_readmail @message variable. Kselvia, by truncating the message means deleberately applying CRLF through code? if so, no I am not doing that.
Regards.
Moazzam
0
There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.
You will need to convert the @message variable to a varchar before you use the REPLACE function. THe risk of truncating is that varchar is maximum length of 8000 characters. If your text is longer than that you will loose the end of it.
declare @MyString varchar(8000)
set @MyString = @message
MyString = replace(replace(@MYString,char(10),''),char(13),'')
however, can youcalrify what the error is you are getting? why are you having problems wiht CRLF?
0
moazzam1574Author Commented:
Hi BillAn1,
Well I am getting this query in mail and this is the error at the bottom of the query that I get.
What SQL xp_readmail reads after the "SR" is CRLF, I have tried several ways to avoid these characters but, was'nt able to resolve this issue, as these lines of xp_readmail doesnt allow any thing like variable assignment and applying functions while this procedure is executed.
these are the lines that I got from sp_processmail, I think the last variable assignment and function application solution you mentioned does'nt fit here.
I have asked my programers to apply some changes at there code to getrid of these CRLF special characters. Lets see what they comeup with. If this replace function would have been worked here properly, it would have been a great stored procedure, no worries at all.
Yes, if CRLF are actually in the middle of calumn names etc, it will cause a problem.
From the look of the data you have here, I think what you need is to replace CRLF with a space
e.g. is the correct name of the column [SR No] ?
in your email it is [SR{CR}{LF}No]
try this (replace the print with EXEC when you are happy) - it replaces CR with ' ' and LF with ''
anyway, to remove CR/LF you can use ;
replace( replace ( @Mystring, CHAR(13),''), CHAR(10), '')