SQL Server - 批量插入而不丢失 CR 或 LF 字符

发布于 2024-12-18 12:46:04 字数 886 浏览 1 评论 0原文

我正在尝试使用批量插入将电子邮件通信导入到数据库表中,但我似乎无法保留 CR 和 LF 字符。让我们考虑以下情况:

CREATE TABLE myTable (
    Email_Id int,
    Email_subject varchar(200) NULL,
    Email_Body TEXT NULL
)

批量插入语句具有以下内容:

codepage = '1250',
fieldterminator = '<3P4>',
rowterminator = '<3ND>',
datafiletype = 'char'

文件包含完整的电子邮件(包括 CR 和 LF 字符)。我想导入数据并包含 CR 和 LF 字符。我读过 BULK INSERT 将每个条目视为一行,但这是否意味着它会删除 CR 和 LF 字符?如果是这样,我可以使用什么来导入此 CSV 文件?我无法访问 SSIS,我更喜欢使用 SQL 代码来完成此操作。

示例数据:

11324<3P4>Read this email because it's urgent<3P4>Haha John, 

I lied, the email was just to mess with you!

Your Nemesis,
Steve

P.S. I still hate you!
<3ND>
11355<3P4>THIS IS THE LAST STRAW<3P4>Steve, 

I have had it with you stupid jokes, this email is going to the manager.

Good day,
John
<3ND>

I am trying to import email communication into a database table using Bulk Insert but I can't seem to be able to preserve the CR and LF characters. Let's consider the following:

CREATE TABLE myTable (
    Email_Id int,
    Email_subject varchar(200) NULL,
    Email_Body TEXT NULL
)

The bulk insert statement has the following:

codepage = '1250',
fieldterminator = '<3P4>',
rowterminator = '<3ND>',
datafiletype = 'char'

The file contains full emails (including CR and LF characters). I would like to import the data and include the CR and LF characters. I have read that BULK INSERT treats each entry as a single row but does that mean it strips out the CR and LF characters? If so, what can I use to import this CSV file? I don't have access to SSIS and I would prefer to use SQL code to do it.

Example data:

11324<3P4>Read this email because it's urgent<3P4>Haha John, 

I lied, the email was just to mess with you!

Your Nemesis,
Steve

P.S. I still hate you!
<3ND>
11355<3P4>THIS IS THE LAST STRAW<3P4>Steve, 

I have had it with you stupid jokes, this email is going to the manager.

Good day,
John
<3ND>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独陪着我 2024-12-25 12:46:04

它应该与回车符和换行符一起导入,即使您在某些工具中看不到它们。我们将以这种方式导入 XSL,它将保留所有行格式。

It should import with the carriage returns and linefeeds, even if you don't see them in some tools. We would import XSL this way and it would preserve all of the line formatting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文