Solved

Query Results to Text File

Posted on 2011-03-15
3
376 Views
Last Modified: 2012-05-11
Is it possible to run a query and have results export to text file in pre-defined column widths with leading zeros if required?

I'm hoping I may be able to build a text file that I can import into a system.  It's 5 fields, all numeric, the results would need to look like this....

00000100002000000000300000000040000000005000000000

First field is 10,000
2nd is 2,000,000,000.....etc
0
Comment
Question by:tobin46
3 Comments
 
LVL 4

Expert Comment

by:qasim_md
ID: 35144316
Check the SQL - BCP QUERY OUT for your requirements.
0
 
LVL 9

Accepted Solution

by:
sshah254 earned 350 total points
ID: 35144339
Use command line SQL - SQLCMD

Use the necessary padding functions from here - http://www.sqlusa.com/bestpractices2005/padleadingzeros/

and Concatenate your results.

Ss
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 150 total points
ID: 35144341
several options

SELECT RIGHT ( replicate('0', 10 ) + cast(10000 as varchar)  , 10 ) +  RIGHT ( replicate('0', 10 )+cat(secondcolumn as varchar)  , 10 ) + ..

if you want to build the file from you can use the osql utitlity

http://msdn.microsoft.com/en-us/library/aa214012(SQL.80).aspx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now