views:

644

answers:

3

I've been trying to import the body from emails into a field in a SQL 2005 database but it keeps losing the formatting (carriage returns, tabs, etc)

Anyway of getting around this?

A: 

What data type if your field in SQL? If you're using a "text" field (nvarchar or similar) then this is likely to be the cause.

If you really need the e-mail body intact then you'll probably need to store it as a blob (binary) field. This will have implications (you should read up about storing binary object in SQL) but it will allow you to store the body of the message.

Presumably you have some good reason why these messages need to be stored IN SQL and not outside (on the file system for example) with only pointers to the messages in SQL?

Martin Peck
Why would text drop carriage returns and tabs? They are all valid text (even ASCII) characters. Not familiar with SQL Server, but sounds like a problem with the import script (which is conveniently not explained), not SQL Server per se.
Matthew Flaschen
If I write to text file or step through code, it keeps the \r\n intact but drops it in the sql field. I've tried using text and varchar - no luck. I've had to str.replace with <BR> to keep the carriage return but now I have read the field in as html. I will try Martin's advice. There must be an easier way though (?)
You might be trying to display \r\n in a web page. But \r\n in HTML does nothing; it's just whitespace. This has little to do with SQL or the database storage.
Andomar
Are you saying that the text you INSERT is different to the test you SELECT from that table? That sounds surprising to me.
Martin Peck
(I meant "text" and not "test")
Martin Peck
A: 

Hi guys, I've managed to find the problem. The dataset I was using was passing the values though as a string. I've changed to char and all formats are preserved. Thanks so much for you help.

A: 

Hi Jody,

What did you changed exactly? I've exactly the same problem. What I'm doing...

Read messages from Exchane and put them into a temporary datatable and after reading all the messages from Exchange I save the datatable contents to my SQL database.

Currently the formatting of the body gets messed up and it is hard to read afterwards!?

Maybe you can help me....

Thanks!

Marcel