Solved

Query Results to Text File

Posted on 2011-03-15
3
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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