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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.