sql – 如何使Microsoft BCP导出空字符串而不是NUL字符?

前端之家收集整理的这篇文章主要介绍了sql – 如何使Microsoft BCP导出空字符串而不是NUL字符?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在努力使这个bcp工具以特定的方式工作. -c开关应该使用chars导出,但是由于某种原因,在记事本中有一个奇怪的字符,就像是UNICODE或其他一些格式.

我想得到这个char,这是数据库中的一个空字符串,作为一个空字符串导出到文本文件中.你如何做到这一点?

解决方法

好吧,看了看网路这是我发现的.想把它放在SO里,所以更多的人都可以使用它.

http://www.techtalkz.com/microsoft-sql-server/147106-how-export-empty-strings-via-bcp.html

@H_502_10@

But when I run bcp,the empty strings are written to the text file
using the ASCII “NUL” character (0x0). Instead,I want the field to be
filled with blanks (0x20).

解:

@H_502_10@

In a text file,an empty string is interpreted as NULL when you bulk
in data. The NUL character is interpreted as the empty string,so
there is consistency. But that does not help much if you are exporting
data to another system….

简单地围绕一个NULLIF该数据库中可能为空的字段,并将其捕获并替换为NULL.这将被转换为^^值^^^^更多的值^^和更多^^所以你得到一个空格而不是NUL字符的双分隔符.

例如.:

...
NULLIF(pri.InstanceName,'') as PerformanceInstanceName,...

希望这有助于某人.

原文链接:https://www.f2er.com/mssql/82244.html

猜你在找的MsSQL相关文章