如何以“真实"方式获得出口产出SQL Server Management Studio中的CSV格式? [英] How to get export output in "real" CSV format in SQL Server Management Studio?

查看:120
本文介绍了如何以“真实"方式获得出口产出SQL Server Management Studio中的CSV格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,我正在SQL Server Management Studio中运行(连接到SQL Server 2005数据库).我想以CSV格式导出数据.不想使用CSV格式(在每个列之间只加逗号),而不想使用真实" CSV格式(在字符串两边加上引号).这样,您可以导出其中包含逗号或引号的数据.

I have a query that I am running in SQL Server Management Studio (connecting to a SQL Server 2005 database). I want to export the data in CSV format. Not wannabe CSV format, where you just stick a comma between each column, but "real" CSV format, where you put quotes around your strings. This way you can export data that has commas or quotes in it.

我看到的所有示例都将自己限制为wannabe格式.我不知道引号的选项在哪里.

All the examples I see limit themselves to the wannabe format. I can't figure out where the option to quote strings is.

如果SSMS确实不具备此基本功能,那么是否还有其他工具可以轻松做到这一点?我不想每次需要数据转储时都不必编写C#程序.

If SSMS is truly incapable of this basic feat, are there other tools that will do it easily? I don't want to have to write a C# program every time I need a data dump.

推荐答案

在SSMS 2012中,有一个选项,在工具"->选项"->查询结果"->"SQL Server"->结果到网格"中,称为引用字符串"保存.csv结果时包含列表分隔符".我不知道这种选择已经存在多久了,但是我对两件事感到困惑:

In SSMS 2012 there's an option for this, in Tools -> Options -> Query Results -> SQL Server -> Results to Grid, it's called "Quote strings containing list separators when saving .csv results". I don't know how long such an option has existed for, but I'm baffled by two things:

  1. 为什么默认情况下未将其打开
  2. 这是一个选项,而不是CSV导出代码的内在部分

这只是一种说法,即默认行为是无法正确导入CSV导出.我已经注意到Excel的作用相同,我必须去看看它是否也有一个选项.

It just defies belief that the default behaviour is to have CSV export that's impossible to import properly. I've noticed Excel does the same, I'll have to go see if that's got an option too.

同时,感谢我的同事在我对CSV导出程序完全没有用的时候向我指出了这一奇异的功能,这是我找到的最佳链接,所以我以为我已将这些知识放在这里以使将来的搜索者受益.

In the mean time, thanks to my colleague who pointed me to this bizarre bit of functionality when I was ranting about how the CSV exporter was completely useless, and this was the best link I'd found about it so I thought I'd put the knowledge here for the benefit of future searchers.

更新

下面的屏幕截图:

这篇关于如何以“真实"方式获得出口产出SQL Server Management Studio中的CSV格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆