当前位置: 动力学知识库 > 问答 > 编程问答 >

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.

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.

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: