SQL Server:如何将数据从一个表复制到另一个表而不使用字符“e”+'被添加到结果中

发布于 2024-12-02 12:13:53 字数 305 浏览 1 评论 0原文

我正在从 Excel 电子表格导入创建的表中复制数据。

以下是我将数据从导入表移动到实际表的操作:

INSERT INTO TableName ([Column1], [Column2])
SELECT [Column1], [Column2] FROM [Sheet1$] 

在第 1 列下执行此操作后,我得到如下记录:

5.31752e+007 当该记录的实际值 (从我导入的表中)是 5046610163

有什么想法吗?

I am copying data from a table created by an Excel spreadsheet import.

Here is what I am doing to move the data from the import table to the actual table:

INSERT INTO TableName ([Column1], [Column2])
SELECT [Column1], [Column2] FROM [Sheet1$] 

After I execute this under column 1 I get records like:

5.31752e+007 when the actual value of that record (from the table I am importing from) is 5046610163

Any ideas?

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

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

发布评论

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

评论(2

独夜无伴 2024-12-09 12:13:53

您没有指定是 Column1 还是 Column2 中包含浮点数据,但这里有一个示例,假设 Column1 是您所需要的。

INSERT INTO TableName ([Column1], [Column2])
SELECT CAST([Column1] AS decimal(38,2)), [Column2] FROM [Sheet1$] 

我经常使用相同的代码转换为 varchar,而无需进行所有格式设置:

SELECT CONVERT(varchar(100), CAST(@value as decimal(38,2)))

You didn't specify whether it was Column1 or Column2 that has the float data in it, but here's an example assuming Column1 is what you need.

INSERT INTO TableName ([Column1], [Column2])
SELECT CAST([Column1] AS decimal(38,2)), [Column2] FROM [Sheet1$] 

I use the same code to convert to varchar without all that formatting quite often:

SELECT CONVERT(varchar(100), CAST(@value as decimal(38,2)))
瑕疵 2024-12-09 12:13:53
INSERT INTO TableName ([Column1], [Column2])
    SELECT UPPER([Column1]), [Column2] 
    FROM [Sheet1$] 

编辑

好的——然后尝试首先打开 Excel 工作表,创建第三列,并将其设为公式 (=UPPER(A1)),其中 A1 实际上是您遇到问题的任何列和。

除此之外,如果您在 Excel 帮助中搜索“科学记数法”,您也会在那里得到一些有限的建议。

编辑 2

或者在 TSQL 中尝试:

INSERT INTO TableName ([Column1], [Column2])
select LTRIM(str(cast([Column1] as real))), [Column2]
FROM [Sheet1$] 
INSERT INTO TableName ([Column1], [Column2])
    SELECT UPPER([Column1]), [Column2] 
    FROM [Sheet1$] 

EDIT

OK -- then try to first open your excel sheet, create a 3rd column, and make it a formula (=UPPER(A1)), where A1 is actually whatever column you're having the trouble with.

Beyond that, if you search for "scientific notation" in Excel help, you'll get some limited advice there as well.

EDIT 2

Or try this in TSQL:

INSERT INTO TableName ([Column1], [Column2])
select LTRIM(str(cast([Column1] as real))), [Column2]
FROM [Sheet1$] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文