简体   繁体   English

将值从SQL Server导出到Excel

[英]Exporting values from SQL Server to Excel

I live in Brasil and decimal separators are commas. 我住在巴西,十进制分隔符是逗号。 For a bunch of reasons, I use dots as decimal separators in SQL Server, which is different from Excel. 由于多种原因,我在SQL Server中使用点作为小数点分隔符,这与Excel不同。

With that being said, I would like to know why the following query 话虽如此,我想知道为什么下面的查询

select 1.0*5

is understood as text in Excel (if so), when copying and pasting, and dots are not converted to commas, while 在复制和粘贴时被理解为Excel中的文本(如果是的话),并且点不转换为逗号,而

select cast(1.0*5 as float)

is understood as float in Excel. 在Excel中被理解为float。

What is the type of result in the first query? 第一个查询的结果类型是什么?

UPDATE 更新

If the query were 如果查询是

select 1.1*5

the result of copy and paste in Excel cell would be 5.5 . 在Excel单元格中复制和粘贴的结果将为5.5 It is not possible to convert this to value in Excel. 无法在Excel中将其转换为值。

While the second query would result in 5,5 . 而第二个查询将导致5,5 I can use the use this value in Excel in an addition operation, for example. 例如,我可以在附加操作中使用在Excel中使用此值。

If you're doing it directly IN Excel, it seems that your regional settings are not seeing that as an operation with a decimal, but rather text. 如果直接在Excel中进行操作,则您的区域设置似乎不会将其视为带有小数的操作,而是带有文本的操作。 If you change your regional settings to US, it would probably resolve it correctly. 如果您将区域设置更改为美国,则可能会正确解决。

The difference between the two is that you are literally telling the value to be cast differently than the default. 两者之间的区别在于,您实际上是在告诉要强制转换的值与默认值不同。 So your regional setting is overridden. 因此,您的区域设置被覆盖。

Excel, as smart as it is, tends to make many assumptions that could be tied to any number of things. Excel本身就很聪明,它倾向于做出许多可以与任何事物联系在一起的假设。 Sometimes you just have to deal with it. 有时您只需要处理它。

In the end, your 2nd query is likely to produce better results. 最后,您的第二次查询可能会产生更好的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM