简体   繁体   English

SQL Server 2008 Express R2格式查询输出到文本文件

[英]SQL Server 2008 Express R2 Format query output to textfile

I have a large table (~ 6GB) which is bigger than my computers RAM that I'm trying to output from a SQL Server data base to a text file in a specific format to be used as an input for another program. 我有一张大表(〜6GB),它大于我要从SQL Server数据库输出到特定格式的文本文件的计算机RAM,以用作其他程序的输入。

The data base looks looks something like this: 数据库看起来像这样:

bought    month     day
   0        11       01
   0        10       07
   1        01       06
   1        04       03
   0        08       03
   0        07       03
   0        02       03
   0        11       05
   1        09       02
  ...       ...     ...

I need the output file to be formatted like this: 我需要将输出文件格式化为:

0 | month:11 day:01
0 | month:10 day:07
1 | month:01 day:06
1 | month:04 day:03
0 | month:08 day:03
0 | month:07 day:03
0 | month:02 day:03
0 | month:11 day:05
1 | month:09 day:02
...

Any suggestions for how to do this? 有关如何执行此操作的任何建议?

If you're running SQL Server management studio, you can output to a file. 如果您正在运行SQL Server Management Studio,则可以输出到文件。

Go to Tools-> Options -> Query Results and you should be able to choose "Results to file" - specify the directory underneath, and run your query. 转到“工具”->“选项”->“查询结果”,您应该能够选择“结果到文件”-在下面指定目录,然后运行查询。

Should just need a bit of string concatenation. 应该只需要一点字符串连接。

SELECT bought + ' | month:' + month + ' day:' + day
FROM tablename

I must confess, I've never tried this on such a large dataset so I can't tell you how it will perform, however once you've entered the query, you can tell SSMS to send the output to a text file as per Bridge's answer. 我必须承认,我从未在如此大的数据集上尝试过此操作,所以我无法告诉您它将如何执行,但是一旦您输入了查询,就可以告诉SSMS按照以下方式将输出发送到文本文件布里奇的答案。

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

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