sql server:我可以在金钱字段中插入$吗

发布于 2024-09-26 17:07:23 字数 425 浏览 0 评论 0原文

我正在将“$5.99”之类的值插入(或尝试插入)到 money 字段中。它不喜欢美元符号,

我实际上是从 csv 文件进行批量插入。 csv 文件中的一列中有 money 并带有美元符号,

您能帮我弄清楚如何将 $ 符号批量插入 <代码>金钱字段?

Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 2 (pricepaid).

我该如何去掉这个标志?

i am inserting values like '$5.99' (or trying to insert) into a money field. it doesnt like the dollars sign

i am actually doing a bulk insert from a csv file. one of the columns in the csv file has money in it with a dollar sign

can you please help me figure out how to do this bulk insert with the $ sign into a money field?

Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 2 (pricepaid).

how do i get rid of the sign?

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

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

发布评论

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

评论(5

东北女汉子 2024-10-03 17:07:23

基于这个问题以及您之前的问题此处这里,我建议您将批量插入到临时保存表中,您可以在其中将“money”字段定义为 varchar。然后再编写一条SQL语句将数据从保持表移至真实表。在此 SQL 语句中,您可以跳过不需要的列,从“money”字段中删除“$”并将其转换为 Money 数据类型等。

Based on this question, as well as your earlier questions here and here, I'd recommend that you do your bulk insert into a temporary holding table, where you could define your "money" field as a varchar. Then write another SQL statement to move the data from the holding table to the real table. In this SQL statement, you could skip unwanted columns, remove the '$' from your "money" field and cast it as a money data type, etc.

喜爱纠缠 2024-10-03 17:07:23

不可以,您不能将货币符号插入货币字段。

它实际上只是一个带有友好名称的十进制(19,4)。

No, you can't insert currency symbols into a money field.

It's really just a decimal(19,4) with a friendly name.

翻身的咸鱼 2024-10-03 17:07:23

作为解决方法,您可以创建一个与目标具有相同架构的表,使用 varchar 列而不是 Money,然后批量插入到该表中。然后更新导入的表以删除“$”并将数据复制到原始目标。

As a workaround, you could create a table with the same schema as your target, using a varchar column instead of money, and bulk insert into that. Then update the imported table to remove the '$' and copy the data to the original target.

天冷不及心凉 2024-10-03 17:07:23

你不能,Money 只是一种数字类型,灵活性比十进制稍差。要使用符号存储,您必须使用 varchar

you can't, Money is just a numeric type slightly less flexible than decimal. to store with the symbol you would have to use a varchar

为你拒绝所有暧昧 2024-10-03 17:07:23

其他人建议使用临时表。如果您使用临时表来保存 CSV 文件中的原始数据,您应该能够从 VarcharChar 直接转换为 Money > 包含 $ 字符的字段(即,不删除它)。

这在 SQL 2008 中对我有用。

Others have suggested a temporary table. If you use a temp table to hold the raw data from your CSV file, you should be able to convert directly to Money from a Varchar or Char field containing a $ character (that is, without removing it).

This worked for me in SQL 2008.

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